How to pass credentials in defaultProxy configuration setting?

The client cannot use my web page because it is located behind the proxy server and they need to provide a username and password in order to go through the proxy server. I have this in my configuration 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 specify a username and password for this proxy setting?

+6
c # proxy sharepoint
source share
1 answer

I do not know how to do this in the defaultProxy section for web.config, but you can definitely do this from the code. Try the following:

 // 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 the proxy web client that you use in your web page.

EDIT:

If I did more homework, I would understand that your problem could be fixed with a single attribute: useDefaultCredentials = "true"

 <system.net> <defaultProxy useDefaultCredentials="true"> <proxy usesystemdefault="False" proxyaddress="http://127.0.0.1:8888" bypassonlocal="True" /> </defaultProxy> </system.net> 
+12
source share

All Articles