我不知道在web.config的defaultProxy部分执行此操作的方法,但是您绝对可以从代码执行此操作。试试这个:
// Get proxy server info from AppSettings section of Web.Config
var proxyServerAddress = ConfigurationManager.AppSettings[ "proxyServerAddress" ];
var proxyServerPort = ConfigurationManager.AppSettings[ "proxyServerPort" ];
// Get proxy with default credentials
WebProxy proxy =new WebProxy(proxyServerAddress, proxyServerPort);
proxy.Credentials = System.Net.CredentialCache.DefaultCredentials();
Web.Config中(配置部分):
<appSettings>
<add key="proxyServerAddress" value="proxy.myhost.com" />
<add key="proxyServerPort" value="8080" />
</appSettings>
,然后分配proxy
您正在使用您的WebPart WebClient的。
编辑:
如果我做了功课多,我就意识到自己的问题可能已经固定有一个属性:useDefaultCredentials =“真”
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" />
</defaultProxy>
</system.net>
感谢。但是这需要成为我的客户的凭据......我不确定我可以得到他的密码。无论如何,我可以解决这个问题? – Prabhu 2010-07-22 17:51:10
更新代码以获取当前登录用户的凭据。 – 2010-07-22 17:52:21
您认为我可以在配置中设置地址和端口,只需在代码中添加proxy.Credentials行即可? – Prabhu 2010-07-22 18:05:34