Reputation: 16724
I needed to get http status code from page loaded in the WebBrowser, I ended up with this solution:
I'm using NavigateError
event from a WebBrowser
ActiveXInstance
instance. But it doesn't work properly: I get only a status code in case of an error (obivous, like method name does suggets) if the page can't be loaded and the user wb.Refresh()
it and load is OK and I have only the old http status error code stored because successfully load doesn't change my http status code. How do I solve this?
public doSomething()
{
SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
axBrowser.NavigateError += new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(axbrowser_navigatorError);
}
public void axbrowser_navigatorError(object pDIsp, ref object URL, ref object frame, ref object statusCode, ref bool Cancel)
{
statuscodeLabel.Text = statusCode.ToString();
int.TryParse(statusCode.ToString(), out httpCode);
}
Upvotes: 3
Views: 6514
Reputation: 61696
WebBrowser
's Refresh
is quite different from the Navigate
/Navigate2
. There is no NavigateComplete2
fired for Refresh. I don't think you can get the status code for Refresh unless you resort to some down-level APP handler hooks. Related: Wpf WebBrowser Refresh.
Upvotes: 1
Reputation: 15175
You can obtain the WebResponse from the NavigationEventArgs on LoadComplete() this should also trigger when the page is refreshed.
Upvotes: 0