How do I know if WebBrowser is navigating to an error page?

for example, we go to http://www.ggg111.com , this is the URL of the error. but the error page is displayed in WebBrowser:

  The webpage cannot be found 
  HTTP 400  
    Most likely causes:
 There might be a typing error in the address. 
 If you clicked on a link, it may be out of date. 

    What you can try: 
      Retype the address.  

      Go back to the previous page. 
      Go to and look for the information you want.  

How do I know if WebBrowser is navigating an error page?

also check this: https://sso.youshang.com/sso/userAuthnAction.do1

  HTTP Status 404 - /sso/userAuthnAction.do1
 type Status report
 message /sso/userAuthnAction.do1
 description The requested resource (/sso/userAuthnAction.do1) is not available.
+4
source share
2 answers

based on this control: http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx

There is a function NavigateError, it is triggered when an error occurs during navigation. here is my modified code:

first enter the argument argument class:

public class NavigateErrorArgs : EventArgs { public object StatusCode { get; set; } public NavigateErrorArgs() : base() { } public NavigateErrorArgs(object statusCode) : base() { this.StatusCode = statusCode; } } 

then add the delegate and event to the ExtendedWebBrowser class:

 public delegate void NavigateErrorHandler(object sender, NavigateErrorArgs e); public event NavigateErrorHandler NavigateError; protected void OnNavigateError(NavigateErrorArgs e) { if (NavigateError != null) NavigateError(this, e); }
public delegate void NavigateErrorHandler(object sender, NavigateErrorArgs e); public event NavigateErrorHandler NavigateError; protected void OnNavigateError(NavigateErrorArgs e) { if (NavigateError != null) NavigateError(this, e); } 

and modify the method in the WebBrowserExtendedEvents class:

 public void NavigateError(object pDisp, ref object URL, ref object frame, ref object statusCode, ref bool cancel) { _Browser.OnNavigateError(new NavigateErrorArgs(statusCode)); } 
+1
source

not sure about this, but ... try, ...

 string check = webBrowser1.DocumentText; if (check.IndexOf("The webpage cannot be found") > 1) { MessageBox.Show("ERROR OCCURED"); //what else you want to do, do here!!! } 

this will lead to the search for the given text, and if found will execute further code

-2
source

All Articles