Automatic proxy detection not working
Hello,
First of all: LINQPad is a GREAT productivity tool and in our company we have many users, using it on a daily base. I love the new feature to great simple chart in the Dump output!
Here is a little issue. The automatic proxy detection of LINQPad is not working properly. In our environment with a NTLM based authenticating proxy and a proxy.pac file in use it is not working.
This is most likely due to not setting the HttpWebRequest.Proxy.Credentials property before sending a request.
Here is a sample C# code where it works and is explained step-by-step:
// create some HTTP web request, e.g. www.microsoft.com
// CAREFUL: some special URLs like www.google.com might be accessible without any proxy credentials as EVERYBODY should be able to use them
// so we use something more special, e.g. "https://www.bundesbank.de"
var url="https://www.bundesbank.de";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
// force the request to be executed without using any cache, for our testing scenario
// in a productive scenario this SHOULD NOT be changed without having mature reason, e.g. a web site handles caching wrongly and deliever
// false results if caching is activated
// CAREFUL: the proxy authentication request is STILL cached. So if you want to test you MUST exit LINQPad after each successful proxy authentication attempt
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
// usually .NET uses the system web proxy
// so the next if line is redundant
// request.Proxy = WebRequest.GetSystemWebProxy();
// or define an explicit proxy
// this shouldn't be necessary except if the proxy handles the request not properly or some exceptional proxy should be used
// that is configured in a special way
// request.Proxy = new WebProxy("proxy.somedomain.com:8080", true)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// here is what needs to DONE
// settings proxy credentials in the code is MANDATORY.
// if you do not set credentials in the code none will be use and hence an anonymous request is sent
// This ALWAYS fails if you have an authenticating proxy server
request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// alternative: create network credentials based on user name and password
// this has to be used if e.g. the applications execution environment uses credentials that have no internet access over the proxy server
// request.Proxy.Credentials = new NetworkCredential("username", "password");
// if you comment the next line it still works
// the request.Credentials are credentials used to access the web site. Those are usually not the default network credentials but some credentials
// for on an Internet authentication protocol, e.g. basic authentication
// request.Credentials = credential;
// do the request
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
reader.ReadToEnd().Dump();
}
}
}
If would be great if this could be fixed.
CAREFUL once again. To test restart LINQPad after each attempt. Else you will see cached results.
-
This is how LINQPad currently works, with the exception of not having an option for Windows credentials. Try the latest beta - it now has a Windows credentials option. Bear in mind that NuGet will ignore this setting.