Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir,

My Project is containing Web services...When internet is disconnected,I have to handle the web exceptions with out throwing any errors..Could you please tell me how to handle it? Kindly give me the solution for this problem.
Posted

1 solution

Include System.Net reference and follow the code below

C#
public static bool CheckForInternetConnection()
{
    try
    {
        using (var client = new WebClient())
        using (var stream = client.OpenRead("http:\\www.google.com"))
        {
            return true;//Tried pinging the site that almost up all the time.
        }
    }
    catch
    {
        return false;
    }
}


Call the above function where you want to check connection availability and throw the error like

C#
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Check Internet Connection.');");
Response.Write("</script>");


By this you can check weather internet is available or not.Further,refer to below links

check internet connection available or not in c# [^]

How to Ping network IP or Hostname in Silverlight Application?[^](Its based on silverlight but will help you bit)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900