I am using WebBrowser to login certain website. Login itself is okay, but it opens new window and I'm losing control of it. Below is code snippet.
HtmlDocument htmlDocAceCounter = this.webBrowser1.Document;
HtmlElement elementLoginID = htmlDocAceCounter.GetElementById("userid");
HtmlElement elementPassword = htmlDocAceCounter.GetElementById("userpasswd");
if ((elementLoginID != null) && (elementPassword != null))
{
elementLoginID.SetAttribute("Value", "someid");
elementPassword.SetAttribute("Value", "somepw");
webBrowser1.Navigate("www.loginURL.com");
}
Problem is that it opens new windows with encrypted web address first and reaches main webpage later. So I can't get the control of logged in page, as well as I don't know how to get there.
Is there anyway to workaround this issue? Any advice would be appreciated.
Edit: It's not duplicate exactly. It's my bad explanation. It first opens new window with loginURL.com, goes through encrypted web address, and then opens logged in page. I don't know how it detects it, but it only approves valid access from direct click popup. I tried many things, but I couldn't cut in the middle. With the referred example, it doesn't reach the encrypted web address and just stays at loginURL.com. I hope it explains better.
Edit2: From
private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed)
{
Processed = true; //Stop event from being processed
//Code to open in same window
this.webBrowser1.Navigate(URL);
//Code to open in new window instead of same window
//Form1 Popup = new Form1();
//Popup.webBrowser1.Navigate(URL);
//Popup.Show();
}
Header has Content-Type: application/x-www-form-urlencoded and PostData has something that can be translated into ascii character. How do I translate them into right url address?
Edit3: I used
this.webBrowser1.Navigate(URL, TargetFrameName, (byte[])PostData, Headers);
instead of
this.webBrowser1.Navigate(URL);
and now I'm getting COMException (0x80004005): Error HRESULT E_FAIL. Does anyone have any idea?