
<system.net> <defaultProxy> <proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" /> </defaultProxy> </system.net>
有没有办法为这个代理设置提供用户名和密码?
解决方法 我不知道在web.config的defaultProxy部分执行此 *** 作的方法,但您绝对可以从代码中执行此 *** 作.试试这个:// Get proxy server info from AppSettings section of Web.Configvar 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>
然后将代理分配给您在webPart中使用的webClIEnt.
编辑:
如果我做了更多的功课,我会意识到你的问题可以用一个属性修复:useDefaultCredentials =“true”
<system.net> <defaultProxy useDefaultCredentials="true"> <proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" /> </defaultProxy> </system.net>总结
以上是内存溢出为你收集整理的c# – 如何在defaultProxy配置设置中传递凭据?全部内容,希望文章能够帮你解决c# – 如何在defaultProxy配置设置中传递凭据?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)