3

In WPF (in code behind) is there a way to detect whether the computer that the client application is running on has access to the internet?

I'm not sure if there is a simple dedicated method / property to check this or whether I would have to try an HttpGet or similar to determine this.

Is there a property or method for this purpose?

-- Lee

Lee Englestone
  • 4,545
  • 13
  • 51
  • 85

2 Answers2

1

It depends on what you consider "access to the internet"

Safest is to add a 'ping' service to the server you wish to connect to and poll that service.

Trying to keep track of the network status is much harder because it is hard to find out whether it is an intranet other type of network.

See this post too

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115
  • Could you clarify what you mean by 'add a ping service' please? – Lee Englestone May 25 '11 at 09:53
  • If it is a WCF service or other web service you need to connect to you can simply add a Ping function that simply returns true. Even simpler: just add an HTML or text page to the server and retrieve it. – Emond May 25 '11 at 09:54
  • Cheers, NetworkChange.NetworkAddressChanged and NetworkChange.NetworkAvailabilityChanged are useful from the post you mentioned – Lee Englestone May 25 '11 at 10:27
  • Just remember that these events do not tell you what kind of access you have. – Emond May 25 '11 at 10:31
0

I don't think there's a simple dedicated method or property.

The simplest solution would be to try to connect to your server and then check the error state.

ChrisF
  • 134,786
  • 31
  • 255
  • 325