I need to configure a website to access a webservice on another machine, via a proxy. I can configure the website to use a proxy, but I can't find a way of specifying the credentials that the proxy requires, is that possible? Here is my current configuration:
<defaultProxy useDefaultCredentials="false"> <proxy usesystemdefault="true" proxyaddress="<proxy address>" bypassonlocal="true" /> </defaultProxy>
I know you can do this via code, but the software the website is running is a closed-source CMS so I can't do this.
Is there any way to do this? MSDN isn't helping me much..
Setting up the credentials for the Proxy Server: In Windows 10 menu, go to Settings (WinKey+I) and search for "Credential Manager". Under Windows Credentials, add a new entry for Windows Credentials. Enter the Proxy Server address (without the port number), your domain user name and the password.
A proxy auto-config (PAC) file defines how web browsers and other user agents can automatically choose the appropriate proxy server (access method) for fetching a given URL. A PAC file contains a JavaScript function FindProxyForURL(url, host) .
Yes, it is possible to specify your own credentials without modifying the current code. It requires a small piece of code from your part though.
Create an assembly called SomeAssembly.dll with this class :
namespace SomeNameSpace { public class MyProxy : IWebProxy { public ICredentials Credentials { get { return new NetworkCredential("user", "password"); } //or get { return new NetworkCredential("user", "password","domain"); } set { } } public Uri GetProxy(Uri destination) { return new Uri("http://my.proxy:8080"); } public bool IsBypassed(Uri host) { return false; } } }
Add this to your config file :
<defaultProxy enabled="true" useDefaultCredentials="false"> <module type = "SomeNameSpace.MyProxy, SomeAssembly" /> </defaultProxy>
This "injects" a new proxy in the list, and because there are no default credentials, the WebRequest class will call your code first and request your own credentials. You will need to place the assemble SomeAssembly in the bin directory of your CMS application.
This is a somehow static code, and to get all strings like the user, password and URL, you might either need to implement your own ConfigurationSection, or add some information in the AppSettings, which is far more easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With