Community discussion forum

Is an Internet Connection Available?

This is a comment thread discussing Is an Internet Connection Available?
  • 10 years ago

    This thread is for discussions of Is an Internet Connection Available?.

  • 6 years ago

    For some reason or another I had to take out a line, the functino I used is as follows:


    Public Function IsConnectionAvailable() As Boolean
       ' 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
       Dim objUrl As New System.Uri("http://www.yoursite.com/")
       ' Setup WebRequest
       Dim objWebReq As System.Net.WebRequest
       objWebReq = System.Net.WebRequest.Create(objUrl)
       Dim objResp As System.Net.WebResponse
       Try
           ' Attempt to get response and return True
           objResp = objWebReq.GetResponse
           objResp.Close()
           objWebReq = Nothing
           Return True
       Catch ex As Exception
           ' Error, exit and return False
           objWebReq = Nothing
           Return False
       End Try
    End Function


    The only change I made was taking out the objResp.Close() after the catch.  It appears that is not created on a failure so the close function errors.


    Nathan

  • 5 years ago

    I get this error when I try to run it on my IIS, please help me!


    Error Type:
    Microsoft VBScript compilation (0x800A0400)
    Expected statement
    /test.asp, line 2, column 40
    Public Function IsConnectionAvailable() As Boolean
    ---------------------------------------^


    I saved the page in a page name test.asp
    and the code to check at the botton of the same page.



    Cipto

  • 5 years ago

    The exception on this errors out if you are offline. To fix this comment out the objresp.close line under the catch exception.


    You can't close something that didn't open


  • 4 years ago

    Helo, I would like to ask if you know how to make internet connection and terminate it in VB.NET? if you know, please send me the code. thanks a lot

  • 4 years ago

    you can not use VB.NET in ASP pages... Active Server Pages does not support .NET.
    You have to use Visual Studio and create a .NET web page, and the file extension will be
    .aspx


    Happy programming!!!

  • 3 years ago

    Real simple and neat chunk of code that could be used in any kind of Application, whether it be a Console or a windows Application and not just a Web Application.

    I had used the same code to make a web request to an ASP page from my Windows Application.

    Regards

     

     

  • 1 year ago

    LooooooooooL
     I first disconnect my ADSL connection, then started this code.

     It tooks a second for my modem to reconnect again and this function returns "TRUE" 

     I will need different solution 


  • 10 months ago
    My.Computer.Network.IsAvailable =)

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback