How to use a proxy server, such as a browser or CredentialCache.DefaultCredentials, different from XP and 7

I can fix the problem with the client where they cannot authenticate through the proxy server by doing the following:

var proxy = WebRequest.GetSystemWebProxy(); proxy.Credentials = CredentialCache.DefaultNetworkCredentials; service.Proxy = proxy; 

This works fine for Windows XP, however on Windows 7 I get 407 (an unauthenticated exception). Does anyone know what the difference is, and more importantly, what do I need to do to get this to work on both OSs?

UPDATE

I have users who check the following:

  • In the registry editor, you can go to HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon and tell me that this value is for CachedLogonsCount. e
  • In the "Start" field, enter the group policy, and you will be able to change the group policy, click on it. Then go to Computer Configuration \ Administrative Templates \ System \ User Profiles \ Delete cached copies of roaming profiles and tell me if it is configured, and if so, what is it installed?

UPDATE FOR BOUNTY

So, I added generosity. I can make a decision from here or just an alternative means to go through a proxy server in Windows 7 ...

Another update

I'm not sure if this is useful or not, but we also do the following:

 service.PreAuthenticate = true; service.Url = "myurl"; service.Credentials = new NetworkCredential(txt_UserName.Text, txt_Password.Text); 

My workaround

This is actually not a solution, but it works for now. I use app.config and set the default proxy using ByPassList so that the proxy is not even used. This can only be done when the proxy server does not currently have a strong firewall. For other clients, I need to make the above work.

+6
source share
4 answers

This piece of code works for me on XP, Win7 and 2008

 var webProxy = new WebProxy(WebRequest.DefaultWebProxy.GetProxy(new Uri({TheURLoftheService}))); webProxy.Credentials = CredentialCache.DefaultCredentials; webProxy.UseDefaultCredentials = true; service.Proxy = webProxy; 
+2
source

it actually looks like they “fixed” it in Win7 :) Can you confirm that both the client and the server indicate http 1.1

Now let's discuss why the browser works in this scenario. IE uses WinINet under the hood, not WinHTTP. If we look at we see that IE sends HTTP / 1.1, but the proxy response responds with HTTP / 1.0. IE still accepts this behavior because there are countless clients and servers on the Internet in the script that still use HTTP / 1.0.

WinHTTP strictly requires HTTP / 1.1 compliance to keep the connection alive and HTTP Keep-Alives are not supported in the HTTP / 1.0 protocol. The HTTP Keep-Alive function was introduced in the HTTP / 1.1 protocol according to RFC 2616. A server or proxy server that expects keep-alive must also correctly implement the protocol. WinHTTP on Windows 7, Windows 2008 R2 is strict in terms of security wrto protocol compliance. The ideal solution is to change the server / proxy server to use the correct protocol and be compatible with RFC.

http://blogs.msdn.com/b/httpcontext/archive/2012/02/21/changes-in-winhttp-on-windows-7-and-onwards-wrto-http-1-0.aspx

+2
source

Will this work?

I use this to install a proxy server, so far we have not encountered an error on all Windows platforms

 Uri address = new Uri("http://your-webservice-address"); //Get User current network credential ICredentials credentials = CredentialCache.DefaultCredentials; NetworkCredential credential = credentials.GetCredential(address, "Basic"); //Get HttpWebRequest HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; //Network Credential should be included on the request to avoid network issues when requesting to the web servic request.Proxy = WebRequest.DefaultWebProxy; request.Credentials = new NetworkCredential(credential.UserName, credential.Password, credential.Domain); 
0
source

It's hard to say based on the code you provided. I suspect these are either your IE settings or your proxy variables.

Check out http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/61b71194-1758-4c7b-89fe-91be7363db13 , this may help.

0
source

All Articles