如何传递defaultProxy配置设置凭据? [英] How to pass credentials in defaultProxy config setting?
问题描述
一个客户端是无法用我的WebPart,因为他是一个代理服务器,他们需要指定一个用户名和密码,让过去的代理。我有这个在我的配置文件现在:
A client is unable to use my webpart because he is behind a proxy server and they need to specify a username and password to get past the proxy. I have this in my config file right now:
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" />
</defaultProxy>
</system.net>
有没有一种方法,以提供用户名和密码,这个代理服务器设置?
Is there a way to supply a username and password to this proxy setting?
推荐答案
我不知道的方式做到这一点在web.config中的defaultProxy部分,但你绝对可以从code做到这一点。试试这个:
I'm not aware of a way to do this in defaultProxy section of web.config, but you can definitely do it from code. Try this:
// 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中(配置部分):
Web.Config (configuration section):
<appSettings>
<add key="proxyServerAddress" value="proxy.myhost.com" />
<add key="proxyServerPort" value="8080" />
</appSettings>
,然后分配代理
来WebClient的你在你的web部件使用。
And then assign proxy
to the webClient you are using in your webPart.
编辑:
如果我做了更多的功课,我会意识到你的问题可能已经固定一个属性:useDefaultCredentials =真正的
If I had done more homework, I would have realized your problem could have been fixed with one attribute: useDefaultCredentials="true"
<system.net>
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" />
</defaultProxy>
</system.net>
这篇关于如何传递defaultProxy配置设置凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!