2

I have a WPF application and I'm using the WebBrowser control to display some content from a public website.

Sometimes in weird edge cases when the network connectivity is flakey, the web browser will show the "This program cannot display the webpage" error page. Is there some way to listen to the WebBrowser to detect when this occurs, so I can load a placeholder?

Jippers
  • 2,635
  • 5
  • 37
  • 58
  • 1
    Another solution is available here: [enter link description here][1] [1]: http://stackoverflow.com/a/14748621/2381779 – Zac Morris Aug 22 '14 at 14:36

2 Answers2

2

You could try using the NavigationService from System.Windows.Controls.Frame as indicated in this MSDN forum post. The WebResponse will always be null for the WebBrowser control in WPF (as described in the post).

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • That tells us how to get the WebResponse, but how do we check for page load failure with the response? – jpmc26 Oct 07 '13 at 18:38
  • I created an example of this as an answer to [this](http://stackoverflow.com/a/29979898/271588) question. – dave May 01 '15 at 00:30
0

In the Navigated event arguments, you can access the WebResponse, so you can access the HTTP response code.

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • My app only calls refresh() on my browser control and it seems the Navigated event never gets fired after the first initialization. Does refresh() not have an event I can listen to? – Jippers Sep 24 '09 at 22:28
  • Apparently not... It's weird that Refresh doesn't trigger Navigated, it looks like a bug – Thomas Levesque Sep 25 '09 at 10:42
  • I'm having a similar issue where in I'm not able to access the HTTP headers available in WebResponse. http://stackoverflow.com/questions/1956590/how-to-get-the-response-headers-while-the-user-navigates-from-page-to-page – Trainee4Life Dec 24 '09 at 11:10
  • 9
    `WebResponse` is always null – SliverNinja - MSFT Feb 08 '12 at 19:28