Include
System.Net
reference and follow the code below
public static bool CheckForInternetConnection()
{
try
{
using (var client = new WebClient())
using (var stream = client.OpenRead("http:\\www.google.com"))
{
return true;
}
}
catch
{
return false;
}
}
Call the above function where you want to check connection availability and throw the error like
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)