Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!


:P
On this page:

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.

 


The Voices of Reason


 

toprak
February 09, 2006

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

The connection is still slow, after changed the web.config.

Is there any other solutions?

http://www.autospital.ch

rbowall
April 24, 2006

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Great info! Spent ages trying to work out why the first http request took half a minute. Afterwards, each request was immediate - As you said just needed to add the following to my code:

Dim w as webclient
w.proxy = Nothing

Silky Shocca
May 29, 2006

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

THANK YOU@!#!@#!@#!@#@!#@!@!#@!!#@#!@#

HOW CAN MICROSOFT BE SO STUPID#!@!@!@#@#!@#

I put that stuff in my config file and stuff started working fast!@#

Configuration and Deployment
September 28, 2006

# ASP.NET Forums - Deploying ASP.NET 2.0

# DotNetSlackers: Slow Http client calls from ASP.NET 2.0 Make sure you check your Proxy Settings!


Rajesh
April 24, 2007

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

I am using Rssfeed control in my page. when it tries to access the web resource using IIS,
it throws the following exception
"The remote name could not be resolved: "
But in ASP.NET development server it is working fine.

In web.config file i have added the follwing entry

  <system.net>
    <defaultProxy>
      <proxy bypassonlocal="False"  usesystemdefault="False"  />      
    </defaultProxy>
  </system.net>


What should i do now? please help me out.

ASP.NET Forums
May 22, 2007

# Deploying ASP.NET 2.0 - ASP.NET Forums


Joel
June 02, 2007

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Thanks - dropped the run time of my function from ~30seconds to ~2-3seconds

K. Scott Allen
July 09, 2007

# K. Scott Allen : Debugging HTTP


Steve R.
September 28, 2007

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Does anyone know what needs to be done to fix this problem in a .NET 2.0 Windows application (Windows Forms)?

Thanks,
Steve

Rick Strahl
September 28, 2007

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

The same solution should apply, although in general you won't have this problem in a WinForms app because WinForms will generally have rights to get at the proxy settings.

Nick H
October 17, 2007

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Will this default behavior of .NET 2.0 also cause the w3wp.exe to work hard (high CPU usage)?

Thanks!

Mohammed Abrar
March 26, 2008

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Very useful post.
pulled my hairs for long to get this.
anyways, thank's Rick

vanishree
June 04, 2008

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

HI,
am very new to asp.net .. i have created one small application.. i have placed tat in iis and if am running in my system through ip am able to run .. but same thin if am running in local network using ip of my system am geeting the following error(10060-connection time out) .. i have added this code in webconfig and am disabling the proxy connection seeting when am running on my system...

<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="False" />
</defaultProxy>
</system.net>

can any one please help me..

Jeff
September 06, 2008

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

I'm a little confused. I'm running a windows app, deployed using click-once, that accesses a web service. Do I make this configuration change in the applications app.config or the web services web.config file?

Thanks

Rick Strahl
September 06, 2008

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

@Jeff - this should only be an issueon the server in web.config. Client side should pick up proper proxy settings.

I also think this has been addressed in .NET 3.0 and later so before you muck with this setting make sure you check and see if this is actually a problem first. Using default settings is always preferrable if they work right <s>...

Jinal
September 30, 2008

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Hi,

I get same error Unable to connect remote server. I made a class library and it going to call third party webservice . Code works fine on my local server and PC.
But when i transfer it remote server it produce error. Console application works fine on remote server. But when i try to use same class lib in webapplication it throws error.

so what may be steps to resolve this issue ?

Thanks.

DotNetKicks.com
January 27, 2009

# Slow Http client calls from ASP.NET 2.0? Make sure you check your Prox

You've been kicked (a good thing) - Trackback from DotNetKicks.com

FR
August 28, 2009

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

THANK YOU RICK!!
After three hours i found the solution here:

Dim wc As HttpWebRequest = WebRequest.Create("https://api.games.betfair.com/rest/v1/channels/1444089/snapshot?username=xxx")
wc.Proxy = Nothing

it was really slow before (18sec!!)
now runs like hell!

Juan
January 17, 2010

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Worked!
I spent hours trying to solve this problem until I found this.
Thanks a lot!

svein
February 06, 2010

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

This stupid thing really kept me pulling my hair for a while until I found your post.

Thanks a lot!

John
May 10, 2010

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Awesome post! It is still paying dividends after all these years! Helped me out a bunch. Thanks!

Jason
March 14, 2011

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

The xml app.config or web.config does not have a place for credentials. If you are behind a company firewall you possibly need to login with your domain credentials. This must be done in code:


//instantiate your web service
//wsStockQuotes = new StockQuoteWebService(....

//setup the proxy info for the web service
System.Net.WebProxy webProxy = new System.Net.WebProxy("domain_name_of_your_proxy_server", 8080);
webProxy.Credentials = new System.Net.NetworkCredential("your_domain_username", "your_domain_pass", "login_domain");
wsStockQuotes.Proxy = webProxy;

//now make calls to your web service
//wsStockQuotes.GetQuote(.....

Mark Schlegel
March 16, 2011

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

I had to change the internet options in Internet Explorer.

Tools->Internet Options->Connections->LAN Settings

I had to uncheck "Bypass proxy server for local addresses". We are using a proxy server, which is set up correctly, I just didn't need the Bypass part checked.

Jon Badgett
March 30, 2012

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Thanks for this post. The problem still exists for .NET 4 apps. I've used your site countless times and just wanted to say thanks.

Michael
September 26, 2012

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Incredible. I was stuck on this for hours. Thank you so much!

Simon
October 08, 2012

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Excellent. Thanks for this. I had a nasty that was only showing up on Windows 7. I thought it was the xml construction in the Web Service call, but that proved to be wrong. Following your post made everything happy. Many, many thanks.

BT
April 02, 2013

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Thaks so much for posting this. After three days of searching for a resolution to my "Unable To Connect to Remote Host" error in WCF with the HttpWebRequest, I actually found the solution here (http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2007/12/03/unable-to-connect-to-the-remote-server.aspx) but you helped him out so I thought I would pass along a thank you because it ultimately helped me too.

Prash
January 23, 2014

# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!

Fantastic!!..even i spent hours and days analysing slowness of my first webservice call , after setting the above configuration settings . it got rid of all those latency making my service faster.

Thanks Rick!!

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