Connecting Tech Pros Worldwide Forums | Help | Site Map

Detecting Internet Connection

Matt Hawley
Guest
 
Posts: n/a
#1: Jul 21 '05
I'm facing a problem where I need to verify that my windows forms application has access to the internet before it can do anything. Currently, the only way I can think of is by creating a HttpWebRequest and point it to the specified URL I wish to connect to later on, and if that throws an error, I know I don't have an internet connection. Is this the best method for detecting an internet connection, or is there some sort of routine that I need to follow that is more tuned for performance?

Thanks for your help!

Matt Hawley, MCAD .NET
http://www.eworldui.net



Elp
Guest
 
Posts: n/a
#2: Jul 21 '05

re: Detecting Internet Connection



"Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
news:eF4Klw5KEHA.1956@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm facing a problem where I need to verify that my windows forms[/color]
application has access to the internet before it can do anything. Currently,
the only way I can think of is by creating a HttpWebRequest and point it to
the specified URL I wish to connect to later on, and if that throws an
error, I know I don't have an internet connection. Is this the best method
for detecting an internet connection, or is there some sort of routine that
I need to follow that is more tuned for performance?

This seems to be the only reliable method to check for an internet
connection. Google will give you other solutions but they generaly rely on
checking if there's a network device configured which doesn't ensure you
that the computer has actually access to the internet. And even if it has
access to the internet, it may be behind a proxy server that restricts this
access to some sites or particular protocols. So the only way to know for
sure if a computer can access your particular site is to try...


Elp
Guest
 
Posts: n/a
#3: Jul 21 '05

re: Detecting Internet Connection



"Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
news:eF4Klw5KEHA.1956@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm facing a problem where I need to verify that my windows forms[/color]
application has access to the internet before it can do anything. Currently,
the only way I can think of is by creating a HttpWebRequest and point it to
the specified URL I wish to connect to later on, and if that throws an
error, I know I don't have an internet connection. Is this the best method
for detecting an internet connection, or is there some sort of routine that
I need to follow that is more tuned for performance?

This seems to be the only reliable method to check for an internet
connection. Google will give you other solutions but they generaly rely on
checking if there's a network device configured which doesn't ensure you
that the computer has actually access to the internet. And even if it has
access to the internet, it may be behind a proxy server that restricts this
access to some sites or particular protocols. So the only way to know for
sure if a computer can access your particular site is to try...


Matt Hawley
Guest
 
Posts: n/a
#4: Jul 21 '05

re: Detecting Internet Connection


Good explanation. Thanks!

Matt Hawley, MCAD .NET
http://www.eworldui.net


"Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
news:eF4Klw5KEHA.1956@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm facing a problem where I need to verify that my windows forms[/color]
application has access to the internet before it can do anything. Currently,
the only way I can think of is by creating a HttpWebRequest and point it to
the specified URL I wish to connect to later on, and if that throws an
error, I know I don't have an internet connection. Is this the best method
for detecting an internet connection, or is there some sort of routine that
I need to follow that is more tuned for performance?

This seems to be the only reliable method to check for an internet
connection. Google will give you other solutions but they generaly rely on
checking if there's a network device configured which doesn't ensure you
that the computer has actually access to the internet. And even if it has
access to the internet, it may be behind a proxy server that restricts this
access to some sites or particular protocols. So the only way to know for
sure if a computer can access your particular site is to try...



Matt Hawley
Guest
 
Posts: n/a
#5: Jul 21 '05

re: Detecting Internet Connection


Good explanation. Thanks!

Matt Hawley, MCAD .NET
http://www.eworldui.net


"Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
news:eF4Klw5KEHA.1956@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm facing a problem where I need to verify that my windows forms[/color]
application has access to the internet before it can do anything. Currently,
the only way I can think of is by creating a HttpWebRequest and point it to
the specified URL I wish to connect to later on, and if that throws an
error, I know I don't have an internet connection. Is this the best method
for detecting an internet connection, or is there some sort of routine that
I need to follow that is more tuned for performance?

This seems to be the only reliable method to check for an internet
connection. Google will give you other solutions but they generaly rely on
checking if there's a network device configured which doesn't ensure you
that the computer has actually access to the internet. And even if it has
access to the internet, it may be behind a proxy server that restricts this
access to some sites or particular protocols. So the only way to know for
sure if a computer can access your particular site is to try...



Steve Podradchik
Guest
 
Posts: n/a
#6: Jul 21 '05

re: Detecting Internet Connection


Yes ... Except that it doesn't always work.

Our WinForms app is heavily dependent on the Internet and our biggest
support problem is people with perfectly valid Internet connections that the
app (using the method below) fails to detect. It appears that .Net has a
great deal of trouble with some proxies that require login (including the MS
one) and, it seems, with VPN connections. We have not been able to resolve
this and it's increasingly frustrating as it's not anything we've been to
repro here although several customers, including IT managers and developers,
have noted this problem. It's very real and very, very frustrating. In all
cases, the customer using IE can access the URL just fine; it only fails
when we do the WebRequest.

Any suggestions would be appreciated.



The code we use is something like (simplified):

Try

wr = CType(WebRequest.Create(UseURL), HttpWebRequest)

Resp = CType(wr.GetResponse(), HttpWebResponse)

Catch we As WebException

'Connection failed

End try

One thing -- we do lock the ProtocolVersion to 1.0 for backwards compat with
some systems. Can that be an issue with some proxies? Is there something
we are specifically supposed to be to ensure that we login to the proxy?

Thanks, Steve

"Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
news:%23MwrR16KEHA.620@TK2MSFTNGP10.phx.gbl...[color=blue]
> Good explanation. Thanks!
>
> Matt Hawley, MCAD .NET
> http://www.eworldui.net
>
>
> "Matt Hawley" <mhawley@!n!o!s!p!a!m!.integrityts.com> wrote in message
> news:eF4Klw5KEHA.1956@TK2MSFTNGP10.phx.gbl...[color=green]
> > I'm facing a problem where I need to verify that my windows forms[/color]
> application has access to the internet before it can do anything.[/color]
Currently,[color=blue]
> the only way I can think of is by creating a HttpWebRequest and point it[/color]
to[color=blue]
> the specified URL I wish to connect to later on, and if that throws an
> error, I know I don't have an internet connection. Is this the best[/color]
method[color=blue]
> for detecting an internet connection, or is there some sort of routine[/color]
that[color=blue]
> I need to follow that is more tuned for performance?
>
> This seems to be the only reliable method to check for an internet
> connection. Google will give you other solutions but they generaly rely[/color]
on[color=blue]
> checking if there's a network device configured which doesn't ensure you
> that the computer has actually access to the internet. And even if it has
> access to the internet, it may be behind a proxy server that restricts[/color]
this[color=blue]
> access to some sites or particular protocols. So the only way to know for
> sure if a computer can access your particular site is to try...
>
>
>[/color]


Elp
Guest
 
Posts: n/a
#7: Jul 21 '05

re: Detecting Internet Connection


Hi Steve,

"Steve Podradchik" <StevePodradchik@hotmail.com> wrote in message
news:uKzhtxcQEHA.1644@TK2MSFTNGP09.phx.gbl...[color=blue]
> Yes ... Except that it doesn't always work.
>
> Our WinForms app is heavily dependent on the Internet and our biggest
> support problem is people with perfectly valid Internet connections that[/color]
the[color=blue]
> app (using the method below) fails to detect. It appears that .Net has a
> great deal of trouble with some proxies that require login (including the[/color]
MS[color=blue]
> one) and, it seems, with VPN connections.[/color]

Have a look at the WebProxy class. In theory, it should allow you to specify
the Web proxy server to be used and a login/password to use for the proxy
server login. I've never had to occasion to test it in a real life situation
but it will maybe solve at least some of your problems


Closed Thread