Web Connections

  • Thread starter Thread starter Dennis C. Drumm
  • Start date Start date
D

Dennis C. Drumm

Does .net Framework 2.0 have anything new to help us detect if a user has an
active internet connection and to send a notice when a connection is
established or dropped?

Thanks,

Dennis
 
Hi,


AFAIK there is no way to know it, you could use some workaround like
1:- Try to establish a connection to a know website (useless if a mandatory
proxy is in place)
2- Try to make a ping to some remote computer (useless if a firewall is
present)
3- Try to resolve a name ( this IMO is the more sure way )


Other than that I cannot think of another way.


cheers,
 
Nothing built in other than attempting a download via HttpWebRequest.
However, with an API, its easy:

[DllImport(@"C:\Windows\System32\wininet.dll")]
// this method will check the internet connection state
public static extern bool InternetGetConnectedState(ref uint connected, uint
reserved);

Peter
 
Hi Dennis,
Welcome to MSDN Newsgroup!

From my experience, there is no notified message which will be sent when
user has an active internet connection. If we want to get current internet
information, I suggest you to call some APIs (for example:
InternetCheckConnection, InternetGetConnectedStateEx ) in WinInet using
P/Invoke mechanism.

I hope the above information is helpful for you. If you have any questions
or concerns, please let me know. Thanks again and have a nice day!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
One word of warning; InternetGetConnectedState is easily confused and can
report an internet connection when there isn't one. It's a good first check,
but you need to do more.

In my old VB6 apps, I use InternetGetConnectedState to make the first check
and, if it reports that there is an internet connection, I attempt to
connect to a known FTP site (our company web site, actually) and only if
that connection can be established do I take it as proof that there is an
internet connection.

Steve


Peter Bromberg said:
Nothing built in other than attempting a download via HttpWebRequest.
However, with an API, its easy:

[DllImport(@"C:\Windows\System32\wininet.dll")]
// this method will check the internet connection state
public static extern bool InternetGetConnectedState(ref uint connected,
uint
reserved);

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Dennis C. Drumm said:
Does .net Framework 2.0 have anything new to help us detect if a user has
an
active internet connection and to send a notice when a connection is
established or dropped?

Thanks,

Dennis
 
It appears that a new class for .net framework 2.0 is PingReply and by using
the Status property one can determine if some known web site is accessible.

This would seem to do the trick and I think would avoid the annoying side
affect of causing someone's computer that only has a dialup connection to
try to connect without being asked to.

What do you all think?

Dennis


Steve Barnett said:
One word of warning; InternetGetConnectedState is easily confused and can
report an internet connection when there isn't one. It's a good first
check, but you need to do more.

In my old VB6 apps, I use InternetGetConnectedState to make the first
check and, if it reports that there is an internet connection, I attempt
to connect to a known FTP site (our company web site, actually) and only
if that connection can be established do I take it as proof that there is
an internet connection.

Steve


Peter Bromberg said:
Nothing built in other than attempting a download via HttpWebRequest.
However, with an API, its easy:

[DllImport(@"C:\Windows\System32\wininet.dll")]
// this method will check the internet connection state
public static extern bool InternetGetConnectedState(ref uint connected,
uint
reserved);

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Dennis C. Drumm said:
Does .net Framework 2.0 have anything new to help us detect if a user
has an
active internet connection and to send a notice when a connection is
established or dropped?

Thanks,

Dennis
 
Hi Dennis,
Nice to see you again!
PingReply could help us get the status of an attempt to send an Internet
Control Message Protocol (ICMP) echo request and receive the corresponding
ICMP echo reply message. We could determine whether or not some web site is
accessible depending on this status.
Thanks for your sharing knowledge. It will benefit others in the newsgroup
facing this issue.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top