Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between WebRequest.DefaultWebProxy and WebRequest.GetSystemWebProxy()?

Tags:

I am wondering what the main differences are between DefaultWebProxy and GetSystemWebProxy(). There're some descriptions on MSDN, but I still feel I need a bit more details to have a better understanding.

Also, let's say I have following options for proxy configuration on my C# winform application

  1. Auto-detect proxy settings
  2. Use system default settings
  3. No proxy

Then which method goes to which option? Is it right to say that Auto-detect proxy somewhat equals Use system default settings?

like image 784
woodykiddy Avatar asked Feb 15 '13 03:02

woodykiddy


1 Answers

Per the MSDN article for WebRequest.DefaultWebProxy, this property will provide the proxy information specified in the app.config file. It looks like the .NET Framework v3.5 MSDN Article is missing this specific detail.

As far as WebRequest.GetSystemWebProxy() goes, the MSDN article for it states that this method will provide the system-wide configured proxy (Control Panel > Internet Options).


This is how I would suggest you implement the three options outlined:

  1. Auto-detect proxy settings
    • Implement your own proxy discovery logic; or
    • Change the system setting to match your application's setting, and use WebRequest.GetSystemWebProxy() (I wouldn't recommend this approach); or
    • Preferably not include this option, and let the user use the corresponding system-wide setting along with the "Use system default settings" option;
  2. Use system default settings
    • Use WebRequest.GetSystemWebProxy();
  3. No proxy
    • Ensure to unset the WebRequest.DefaultWebProxy and the WebRequest.Proxy properties;

Edit: If no proxy is configured in app.config WebRequest.DefaultWebRequest is almost the same as WebRequest.GetSystemWebProxy() (at least for .NET 4.5). The difference is that WebRequest.GetSystemWebProxy() will run the PAC script (if any) for proxy definition.
Thanks to Gabrielius and to 23W for the comments below.

like image 139
Jesse Avatar answered Oct 12 '22 18:10

Jesse