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);
}