Question

I have a .NET application (WPF but that doesn't really matter) running on Windows 7 (x86). I want to connect to the internet from my application to call a web service. When there is a wifi connection, I want to use that. If there is no wifi connection, I want to automatically connect to a GPRS connection setting defined in the OS (e.g. in internet explorer's connection settings).

In the days of dial-up, you could specify both a LAN connection and a dial-up connection in IE, and when IE detected that there was no LAN, you were asked if you wanted to connect to dial-up.

In this case, I have wifi instead of LAN and GPRS instead of dialup and I'm not using IE but a custom .NET application. Prompting the user with an OS dialog would be OK.

I can do this myself with the managed wlan API (codeplex) and the GPRS chipset manufaturer's SDK, but I want to know if there is a way that Windows 7 can do this for me.

Was it helpful?

Solution

Use DefaultWebproxy available on a WebRequest. The DefaultWebProxy property reads proxy settings from the app.config file. If there is no config file, the current user's Internet Explorer (IE) proxy settings are used.

For Ex-

webRequest.Credentials = CredentialCache.DefaultCredentials;
                    if (WebRequest.DefaultWebProxy != null)
                    {
                        webRequest.Proxy = WebRequest.DefaultWebProxy;
                        webRequest.Credentials = CredentialCache.DefaultCredentials;
                        webRequest.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    }
                    else
                    {
                        Trace.WriteLine("Unable to detect proxy.");
                    }

Check out these links -

  1. http://msdn.microsoft.com/en-us/library/5t9y35bd.aspx
  2. http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx
  3. http://msdn.microsoft.com/en-us/magazine/cc300743.aspx
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top