Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:29:47+00:00 2026-06-15T18:29:47+00:00

I wrote this function to check if an internet connection is available: bool IsOnline()

  • 0

I wrote this function to check if an internet connection is available:

    bool IsOnline()
    {
        try
        {
            var request = (HttpWebRequest)WebRequest.CreateHttp("http://www.google.com/");
            request.Timeout = 2000;

            var response = (HttpWebResponse)request.GetResponse();
            return ((int)response.StatusCode) < 400;
        }
        catch (Exception) { return false; }      
    }

It seems to work in almost all cases however under my work network it return false after a timeout error while the connection is available.

Note:
– this function return false but I can go online with a webbrowser component in my WPF application
– the connection is pretty good. (so it is impossible to spend more than 2sec in loading google.com)
– I’m behind a proxy configured correctly in Control Panel/Internet Options/Connection

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:29:48+00:00Added an answer on June 15, 2026 at 6:29 pm

    As workaround I changed my function in this way:

    bool IsOnline()
    {
        try
        {
            var request = (HttpWebRequest)WebRequest.CreateHttp("http://www.google.com/");
            request.Timeout = 2000;
    
            var registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", false);
            var proxy = (string)registry.GetValue("ProxyServer");
            var isProxyEnabled = (int)registry.GetValue("ProxyEnable");
            if (isProxyEnabled>0)
            {
                request.Proxy = new WebProxy(proxy, true, null, System.Net.CredentialCache.DefaultNetworkCredentials);
            }
    
            var response = (HttpWebResponse)request.GetResponse();
            return ((int)response.StatusCode) < 400;
        }
        catch (Exception) { return false; }      
    }
    

    If I try to use WebRequest.GetSystemWebProxy() I get a IWebProxy (WrappedWebProxy) that has the same settings as the one that I manually build but it does not work. It recognize all addresses as local also if I do not have check the “Bypass proxy server for local addresses”.

    Then if I change through the debugger the bypasslocal flag it works. It’s so strange that looks like a bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this code: function json() { var url=http://192.172.2.23:8080/geoserver/wfs?request=GetFeature&version=1.1.0&outputFormat=json&typeName=topp:networkcoverage&CQL_FILTER= topp:CELL_ID='410-07-301-31781' Or topp:CELL_ID='nnn'&callback=?; jQuery.getJSON(url,function(data){alert(Symbol: +
I wrote this function in php to check user/pass against account on linux server.
I have written this ajax request for username checking... function check_username() { var username
I wrote this snippet of javascript/jQuery to change a check box. http://jsfiddle.net/johnhoffman/crF93/ Javascript $(function()
I wrote this function to make columns sortable. I want to rearrange divs based
I wrote this function for filling closed loop, pixvali is declared globally to store
I wrote this function to get the unread count of google reader items. function
I wrote this function to get a pseudo random float between 0 .. 1
I wrote this function to communicate with an external program. Such program takes input
So I wrote this function that is given possible numbers, and it has to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.