I posted about this issue before indirectly, but I think it bears repeating as a dedicated topic. I've seen a fair number of questions about this on various forums recently. 

 

The problem: You're using some sort of HTTP client from an ASP.NET 2.0 or low rights .NET 2.0 application and it's very slow to connect to a Web server to retrieve HTTP content. This could be with WebRequest, WebClient, XmlDom/Reader or a Web Service Client.

 

In .NET 2.0 the default proxy configuration settings have changed. In .NET 1.1 the default proxy settings basically were set for no proxy, which meant that if you connected to the Web using HttpWebRequest, WebClient, an XmlDom/Reader object or a Web Service it would try to connect directly. If you wanted to use the machine default proxy settings you had to explicity assign the DefaultProxy:

 

Request.Proxy = WebProxy.GetDefaultProxy();

 

In .Net 2.0 the above behavior becomes the default implicitly. .NET 2.0 uses the machine’s default proxy configuration by default. The default proxy configuration is the configuration you see in the IE proxy configuration settings.

 

Now for most desktop applications, this is sensible – you’d want to use the system proxy settings to make a connection so your app doesn’t have to manually set proxy configuration settings. However, if you’re running a Web application or a limited rights application downloaded from the Web or otherwise running in a low security environment, you’ll run into problems the default proxy retrieval. The problem is that low access accounts don’t have access to the machine proxy configuration settings which are stored in the registry under HKLM keys.

 

So if you’re running ASP.NET with NETWORK SERVICE as your host account – you can’t get at the proxy settings. I ran into this a while back where I had some aggregate RSS feeds from various sites I was displaying on a page of my site. It was taking upwards of 10 seconds for these feeds to get retrieved even from my own site on the local machine! The problem was the proxy settings. .NET apparently tries to retrieve the proxy settings and looks in various places to get them, fails and eventually gives up and simple directly connects. It works, but it’s VERY VERY slow.

 

Luckily the solution is simple. You can override the proxy settings in the .Config file for your application using the defaultProxy key in the system.net section. The following disables automatic Proxy detection:

 

<configuration >

  <system.net>

    <defaultProxy>

      <proxy bypassonlocal="true" usesystemdefault="false" />

    </defaultProxy>

</system.net>

</configuration>

 

Another more explicit option in code is to explicitly set the Proxy property of the Http object (WebRequest, XmlDom, Web Service Client etc.) to null which essentially has the same effect.