I would like to override the EventArgs
of the event WebBrowserDocumentCompleted
. I can't create a personal event handler, because I have no idea when I should fire the event DocumentDownloadCompleted
. The data I would like to add to the EventArgs
is the OriginalPageLink
.
I'm trying to download a page, but I'm redirected to a login page (only once). I've setup a way to login, but then I would like to re-try navigating to the original page, but I don't have it any more. I could set a global variable to track each time that link, but, is there a way to edit EventArgs
? Do I need to also modify WebBrowserDocumentCompletedEventHandler
.
My code looks like
private void Submit_Click(object sender, EventArgs e)
{
webBrowser1 = new WebBrowser();
webBrowser1.AllowNavigation = true;
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
webBrowser1.Navigate(OriginalPageLink);
}
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.ToString().Contains("login.smlogin.ibb.ubs.net")) {
loginWithWEBSSO(webBrowser1);
webBrowser1.Navigate(***e.OriginalPageLink***);
} else {
string mybody = webBrowser1.Document.Body.InnerText;
}
}
Thank you in advance for any suggestions.
Marco
You just need to latch onto the
WebBrowser.Navigating
event to keep track of the navigation history using some sort of collection. Go back to the previous page before the login occurs. TheNavigate
event will trigger the Navigating and remove the previous URL, so you need to manage a collection or just limit which items get managed in your state.