.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Network >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Check for Internet Connection availability in ASP. Net

Posted By:Prasanti Prusty       Posted Date: December 17, 2009    Points: 10    Category: Network    URL: http://www.dotnetspark.com  
 

Check for Internet Connection availability in ASP. Net using Vb.Net.

Using below code you can also get response and you can display to the end user

Code :

Partial Class frmChkInternetConnection
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If fnChkInternetConn() Then
            Response.Write("Congrats ! Internet Connection is Available.")
        Else
            Response.Write("Sorry ! Internet Connection is not Available.")
        End If
    End Sub

    Public Function fnChkInternetConn() As Boolean
        Dim objreq As System.Net.HttpWebRequest
        Dim objres As System.Net.HttpWebResponse
        Try
            objreq = CType(System.Net.HttpWebRequest.Create("http://www.google.com"), System.Net.HttpWebRequest)
            objres = CType(objreq.GetResponse(), System.Net.HttpWebResponse)
            objreq.Abort()
            If objres.StatusCode = System.Net.HttpStatusCode.OK Then
                Return True
            End If
        Catch weberrt As System.Net.WebException
            Return False
        Catch except As Exception
            Return False
        End Try
    End Function
End Class


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend