Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know whether WebBrowser navigating a error page?

Tags:

c#

for example, we navigating to http://www.ggg111.com, it's a error URL. but in WebBrowser it display a error page with this:

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 to know whether WebBrowser navigating a 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.
like image 956
Cooper.Wu Avatar asked Nov 15 '22 15:11

Cooper.Wu


1 Answers

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

there is NavigateError function, fires when an error occurs during navigation. here is my modified code:

add event argument class first:


public class NavigateErrorArgs : EventArgs
{
    public object StatusCode { get; set; }

    public NavigateErrorArgs()
            : base()
    { }

    public NavigateErrorArgs(object statusCode)
            : base()
    {
       this.StatusCode = statusCode;
    }
}

then add delegate and event in class ExtendedWebBrowser:


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 method in class WebBrowserExtendedEvents:


public void NavigateError(object pDisp, ref object URL, ref object frame, ref object statusCode, ref bool cancel)
{
    _Browser.OnNavigateError(new NavigateErrorArgs(statusCode));
}
like image 63
Cooper.Wu Avatar answered Dec 18 '22 19:12

Cooper.Wu