Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Dim w as webclient
w.proxy = Nothing
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
HOW CAN MICROSOFT BE SO STUPID#!@!@!@#@#!@#
I put that stuff in my config file and stuff started working fast!@#
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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.
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Thanks,
Steve
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Thanks!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
pulled my hairs for long to get this.
anyways, thank's Rick
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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..
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Thanks
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your 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>...
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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.
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
I spent hours trying to solve this problem until I found this.
Thanks a lot!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Thanks a lot!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
//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(.....
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
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.
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Thanks Rick!!
# re: Slow Http client calls from ASP.NET 2.0? Make sure you check your Proxy Settings!
Is there any other solutions?
http://www.autospital.ch