We’re working on a wrapped WebBrowser component. We’d like to display one page (e.g. oursite.com/thispage.html) if the user is online and another page (e.g. C:\somewhere\thispage_offline.html) if the user is offline. I’m able to to properly display both pages, but my issue is detecting the online/offline status.
I tried
WebBrowser.IsOffline; however it seems that only relays the Offline Mode status, not whether or not the computer is actually able to reach the internet.
Is there a way to detect this from the WebBrowser component? Is there a way at all?
Thanks for all your help!
The simplest way to check for internet connectivity is to ping your server.
Try this code:
Alternatively, you can try using the
WebRequestclass to send a request to a simple page on your site and see whether it succeeds. This is a better option because it will also make sure that IIS (or Apache) is running on the server.