0

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?

a1cd
  • 17,884
  • 4
  • 8
  • 28
Hawos
  • 33
  • 6

2 Answers2

1

Use FrameLoadEndEventArgs for HttpStatusCode.

Eg:

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

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);
RBT
  • 24,161
  • 21
  • 159
  • 240
martian481
  • 1
  • 1
  • 4