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 (configuration section):
<appSettings>
<add key="proxyServerAddress" value="proxy.myhost.com" />
<add key="proxyServerPort" value="8080" />
</appSettings>
And then assign proxy
to the webClient you are using in your webPart.
EDIT:
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>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…