.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 >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to check Internet connection in asp.net

Posted By: Ramesh     Posted Date: December 16, 2009    Points:2   Category :ASP.Net
Hi,

How to check Internet connection in asp.net. Please help me I am using Asp.net with C#.

if the Internet connection is not available than we have to notify user that Internet connectivity is not available Please check the connection

Regards
Ramesh

Responses
Author: Prasanti Prusty             
Posted Date: December 17, 2009     Points: 5   

Hi Ramesh ,

Write the code in page load and call the function "fnChkInternetConn()" to chk internet connection.

    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




Thankx,
Chikul

Regards,
Prasanti
Author: Ramesh             
Posted Date: December 17, 2009     Points: 5   

Thanks a lot Chikul.

Regards
Ramesh

Author: Prasanti Prusty             
Posted Date: December 17, 2009     Points: 5   

Most Welcome

Regards,
Prasanti
Author: nishithraj             
Posted Date: December 18, 2009     Points: 5   

You can ping to a website and check as in the url
http://www.devasp.net/net/articles/display/639.html



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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