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
- Auto-detect proxy settings
- Use system default settings
- No proxy
Then which method goes to which option? Is it right to say that Auto-detect proxy
somewhat equals Use system default
settings?
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:
- 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;
- Use system default settings
- Use
WebRequest.GetSystemWebProxy()
;
- 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.