Monday, January 30, 2012

Check Internet Connection Availablity using Asp.Net

we can check status of internet connection using  asp.net page.

using C#

protected void  btn_Click(object sender, EventArgs e)
{
        System.Uri objUrl = new System.Uri("http://www.criticalcodes.blogspot.com/");
        // Setup WebRequest
        System.Net.WebRequest objWebReq = default(System.Net.WebRequest);
        objWebReq = System.Net.WebRequest.Create(objUrl);
        System.Net.WebResponse objResp = default(System.Net.WebResponse);
        try
        {
            // Attempt to get response and return True
            objResp = objWebReq.GetResponse();
            objResp.Close();
            objWebReq = null;
            ScriptManager.RegisterStartupScript(this, typeof(string), "alertUpdateStatus", "alert('connection available'); ", true);
        }
        catch (Exception ex)
        {
            // Error, exit and return False
            objWebReq = null;
            ScriptManager.RegisterStartupScript(this, typeof(string), "alertUpdateStatus", "alert('connection not available'); ", true);
        }
}











No comments:

Post a Comment