Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

On this page:

I’m in the final stages of getting my West Wind Web Store app ported over to 2.0 by getting rid of all of the obsolete function calls and other non fatal messages. Frankly most of these deprecated APIs changes are lame and for the most part simple name changes or attaching the same logic to some other object. While I think cleaning up interfaces is not a bad idea, deprecating many of these old apis in this ways is a pain. I know, I know I can turn this off, but this code ships to customers and they'd have to turn it off too...


Anyway, I bit the bullet and went through and cleaned most of this up. The vast majority of these where related to ADO.NET parameters and ASP.NET Page Script objects, which have all moved to a separate Scripting object. Most of the stuff is just using a different method or possibly a different subobject - pure manual labor.


The last one I’m left with though is one I don’t know how to replace.


Warning         1        'System.Net.WebProxy.GetDefaultProxy()' is obsolete: 'This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202'          D:\projects2005\wwIPStuff\wwHTTP.cs     500     31      wwIPStuff


I use GetDefaultProxy in my wwHttp component to automatically use Internet Explorer settings by default. One of the reasons I need to do this is so I can debug my HTTP requests with Fiddler which works through the IE settings.


I think from the reading that I’ve done on this, that .NET 2.0 now uses this setting by default now, so it’s probably no longer necessary to use this method, but I wonder then how you’d turn this behavior off.


Anybody know what the recommended replacement procedure is?



HTTP Retrieval Problems in ASP.NET 2.0 applications 

As a side note I’ve noticed that there is a problem with Whidbey and Proxy behavior. Under ASP.NET 2.0 doing XmlDocument.Load() or opening an Http Connection with HttpWebRequest, the connection seems to hang for about 10 seconds before starting to retrieve data on the first data retrieval.


This only happens under ASP.NET operation (or some other non-UI desktop account) – in a Console test of the same identical code runs fine without hesitation.


You can find out more about this here – I posted this as a bug on the feedback center:





MSDN Feedback Center

Incidentally I have to say that MSDN Feedback center is a royal pain in the ass to use. It’s next to impossible to determine when an how a bug was updated and whether I need to respond to a bug or not. I see changes but often it’s just a status change without any action required. At one time I had 10 open issues and trying to keep up with it, I ended up missing a few valuable messages and feedback.


The process of submitting also is too tedious. I really gotta wonder WTF there isn’t a Web Service built straight into Visual Studio to do this. This would save a significant amount of re-typing all the information that the system can pick up automatically for me like the version number, language etc. When I fill out a bug I want to just fill out the error info and not take 5 minutes just to get to the point of actually filling a bug report.


The Voices of Reason


Blair Jennings
July 12, 2005

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

The latest MSDN mag (August 2005) has a great article on just this subject. Just use this call:

IWebProxy aProxy = WebRequest.DefaultProxy;

and you are done.


Rick Strahl
July 17, 2005

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Thanks Blair. Excellent article!


The solution to the problem is to explicitly disable default proxy support in web.config, which essentially forces a direct connection:
<proxy usesystemdefault="False"/>

Voila HTTP access is fast again.

July 18, 2005

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Nice to know. I've got several spiders that I'll need to update code on it looks like.

Rick Strahl
July 25, 2005

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

FWIW, the property Blair was talking about is the static:

WebRequest.Proxy = HttpWebRequest.DefaultWebProxy;

This still begs the question on how to turn off proxy detection since auto-proxy now appears to be the default. Assigning null to the proxy? Declaratively I suspect we can use the same defaultproxy settings in the .config file to turn this off.

November 29, 2005

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?


I think I have same problem,
I copied my ws to another machine in my intranet, with the release of .net 2.0.

now when after deploying my client (winform which connects to ws), I get the following error:

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

Now , I wanted to know why my dev computers are fine , when others are throwing this exception? should I modify the machine.config or the app.config , is it client-or-server side problem??

Please give me the new config explicitly!

Thanks in advance,

Ilan :)

February 02, 2006

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

I have the same issue as that of Breezback, i tried using proxy approach but no help.
The environment i put my code does not have any proxy settings in the IE, and i dint get any proxy error while adding a webreferance there

June 01, 2006

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?


I have the same problem with Breezback.
I tried to call a webservice from a desktop application and it returned that error.

Anybody knows how to solve this problem?

Thanks in advance..

eggheadcafe.com articles
October 02, 2006

# aspnet Deploying ASP.NET 2.0

# DotNetSlackers: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0

# Deploying ASP.NET 2.0 - microsoft.public.dotnet.framework.aspnet | Google Groups

April 23, 2007

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

solution with
IWebProxy aProxy = WebRequest.DefaultProxy;

is pretty good and it solved the block.

my question is how about on WINCE, as WebRequest.DefaultProxy is not supported by .net compact framework...



Rick Strahl
June 10, 2007

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Rick - I think you can probably set the proxy to null and that should work.

# Google Groups: microsoft.public.dotnet.framework.aspnet

July 25, 2007

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Rick - the system.net configuration options enable you the configure the default proxy as you need. Eg, mine is:

<defaultProxy enabled="true" useDefaultCredentials="true" >
<proxy autoDetect="True" scriptLocation="http://wpad.premiers.qld.gov.au/wpad.dat"/>

The above does exactly what IE does.

Im sure you can configure the default to what ever you require.

Nick H. W.
December 06, 2007

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Hi pepole:

I have been through ways of failure for this, finally got right one.

1. refresh web service, enter the link like : http://testgsrs/Safety_Incident.asmx

2. In Reference.cs, change following clause to the new one:

this.Url = global::FA.Properties.Settings.Default.FA_testgsrs_Safety_Incident;

it fixed.

I have tried following ways in the assumption that proxy setting is the main reason. but not.

Nick. H. W.


<proxy usesystemdefault="False"/>
<defaultProxy enabled="true" useDefaultCredentials="true" >
<proxy autoDetect="True" scriptLocation="http://ccm.ga.local/proxy.pac"/>

// in .cs

//System.Net.WebRequest.DefaultWebProxy = System.Net.HttpWebRequest.DefaultWebProxy; //Proxy,
//System.Net.IWebProxy aProxy = System.Net.WebRequest.DefaultWebProxy; // FASafetyConnection, DefaultProxy
//System.Net.WebRequest.DefaultWebProxy = null;

December 16, 2008

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Hi Guys.

I don't understand the posts above. What should I do to this line of code:

this.WebRequest.Proxy = WebProxy.GetDefaultProxy();

Visual Studio doesn't like:

this.WebRequest.Proxy = WebRequest.DefaultProxy;

Please explain in simple terms.


July 20, 2009

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

If you are using VS - then intellesense should have showed you the proper method

this.WebRequest.Proxy = WebRequest.DefaultWebProxy;

August 04, 2009

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Use the following
WebRequest.Proxy = HttpWebRequest.DefaultWebProxy

August 23, 2010

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Thanks, Michael.
Your solution worked.

September 19, 2011

# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?

Michael's comments helped. Setting the complete proxy settings in web.config did the trick.

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2019