// By Suneel Kumar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ConnectionProperty
: System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
if
(isInternetAccess())
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"", "alert('Internet
Access')", true);
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"", "alert('No
Internet Access')", true);
}
}
public bool
isInternetAccess()
{
// By Suneel Kumar
// Returns True if connection is available
// Replace www.yoursite.com with a site that
// is guaranteed to be online - perhaps your
// corporate site, or microsoft.com
Uri objUrl = new
System.Uri("http://www.google.com/");
//Setup WebRequest
System.Net.WebRequest objWebReq;
objWebReq = System.Net.WebRequest.Create(objUrl);
System.Net.WebResponse objResp = null;
try
{
//Attempt to get response and return True
objResp = objWebReq.GetResponse();
objResp.Close();
objWebReq = null;
return true;
}
catch
{
// Error, exit and return False
objWebReq = null;
return false;
}
}
}
Labels: Javascript , Microsoft .Net
Responses
0 Respones to "Check Internet Access on client Machine using ASP.Net"
Post a Comment