Is there any possibility to get status code i.e. (200,301,302) after loading html page in CefSharp C#?

708 Views Asked by At

I'm facing a problem that I can't get a response status code after loading the HTML website in CefSharp C# project. There are a few methods like OnLoadingStateChange called after loading the new page in a browser.

The main problem is I do no how to get the status response code (200,301,302, etc.) associated with the loaded page. How to do it?

2

There are 2 best solutions below

0
On

add this method:

private void CheckStatus(object sender, FrameLoadEndEventArgs e)
{        
     if (e.HttpStatusCode != 200)
     {       
          MessageBox.Show("Server Down or wrong URL");
          System.Environment.Exit(0);
      }
}

and inside the main class :

InitializeComponent();        
Cef.EnableHighDPISupport();
var browser = new ChromiumWebBrowser("https://www.google.com");        
browser.FrameLoadEnd += CheckStatus;
this.Controls.Add(browser);
0
On

Use FrameLoadEndEventArgs for HttpStatusCode.

Eg:

private async void webBrowser(object sender, FrameLoadEndEventArgs e){
   if (e.HttpStatusCode == 400)
   {
      // do something
   }
}