Detect if offline - in C # WebBrowser component?

We are working on a wrapped WebBrowser component. We want to display one page (eg oursite.com/thispage.html) if the user is online and another page (eg C: \ where \ thispage_offline.html) if the user is offline. I can display both pages correctly, but my problem is detecting online / offline status.

I've tried WebBrowser.IsOffline ; however, it seems that only the offline status relay is independent of whether or not the computer can actually reach the Internet.

Is there a way to detect this from within the WebBrowser component? Is there a way at all?

Thank you for your help!

+2


source to share


2 answers


The easiest way to test your internet connection is to test your server.

Try this code:



public static bool IsOnline() {
    var pinger = new Ping();

    try {
        return pinger.Send("oursite.com").Status == IPStatus.Success;
    } catch(SocketException) { return false; } catch(PingException) { return false; }
}

      

Alternatively, you can try using a WebRequest

class
to send a request to a simple page on your site and see if it succeeds. This is the best option as it also ensures that IIS (or Apache) is running on the server.

+6


source


What if you used the Ping class to see if a site is available?



+3


source







All Articles