如何使用Internet Explorer使用的代理服务器在ASP.NET应用程序 [英] How to use the proxy used in Internet Explorer in an ASP.NET application
问题描述
在我的ASP.NET应用程序中,我使用WebRequest类,我想使用默认的系统代理。这里是code我使用。
In my ASP.NET application I am using the WebRequest class and I want to use the default system proxy. Here is the code I am using.
private static bool CheckIfUriIsReachable(string uri)
{
bool reachable = true;
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "HEAD";
var proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = proxy;
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException)
{
reachable = false;
}
finally
{
if (response != null)
{
response.Close();
}
}
return reachable ;
}
当作为控制台应用程序的一部分运行这工作得很好 - 它正常工作时的一部分运行拿起系统代理(我假设在PC上签了字的用户的IE代理),但是,这并不工作在同一台机器上的ASP.NET应用程序。无代理发现。
This works perfectly well when run as part of a console application - it correctly picks up the system proxy (I assume the IE proxy for the signed-on user on the PC), However, this does not work when run as part of an ASP.NET application on the same machine. No proxy is found.
我想这是因为ASP.NET下不具有在系统注册表中的IE代理设置用户帐户下运行。我曾尝试包括在web.config文件中的以下但这不起作用。
I assume this is because ASP.NET is running under a user account that does not have an IE proxy setting in the system registry. I have tried to include the following in the web.config file but this does not work.
<system.net>
<defaultProxy>
<proxy usesystemdefault="true" />
</defaultProxy>
</system.net>
我的问题是如何建立一个ASP.NET 3.5应用程序正确使用IE浏览器所使用的默认代理?
My question is how to setup an ASP.NET 3.5 application to correctly use the default proxy used by IE?
推荐答案
有没有全系统的默认代理。因此,你只能使用日当前用户的配置。如果不存在这样的配置,则有一个问题。
There is not system-wide default proxy. Thus you can only use th configuration of the current user. If there is no such configuration, you have a problem.
您可以尝试使用代理服务器配置中运行ASP.NET应用程序的应用程序池一个用户下或可考虑组策略,其中,据我所知,做支持设置系统级代理。
You can try to run the app pool of your ASP.NET application under a user with a proxy configuration or look into group policies, which, AFAIK, do support setting a system-wide proxy.
这篇关于如何使用Internet Explorer使用的代理服务器在ASP.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!