Thursday, August 23, 2007

4315.aspx

WebProxy.Credentials does not work when KeepAlive = false in .NET 1.1

While working on the next version of SocketProxy I came along a strange issue with Proxy NetworkCredentials not working.


This is the code:


System.Net.WebProxy uplinkProxy;               


 


uplinkProxy = new System.Net.WebProxy(txtProxy.Text);


uplinkProxy.Credentials = new System.Net.NetworkCredential(txtUser.Text, txtPassword.Text);                                         


 


System.Net.HttpWebRequest request = (HttpWebRequest) WebRequest.Create(txtSite.Text);


request.KeepAlive=false;


request.Proxy = uplinkProxy; 


 


System.Net.HttpWebResponse response = (HttpWebResponse) request.GetResponse();     


response.Close();



Using WireShark (ex Ethereal) I noticed that my proxy authentication was not passed:
Request



GET http://www.microsoft.com/ HTTP/1.1
Proxy-Connection: Close
Host: www.microsoft.com


Reply



HTTP/1.1 407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied.  )
Proxy-Authenticate: Negotiate
Proxy-Authenticate: Kerberos
Proxy-Authenticate: NTLM
Proxy-Authenticate: Basic realm="..."



The interesting thing is that it works fine with HTTPS which is why I did not notice the problem earlier.


Request:



CONNECT www.microsoft.com:443 HTTP/1.1
Proxy-Authorization: Negotiate TlRMT...==
Host: www.microsoft.com:443


Reply



HTTP/1.1 407 Proxy Authentication Required ( Access is denied.  )
Proxy-Authenticate: Negotiate TlRMT..=
Content-Length: 0    


Automatic second request:



CONNECT www.microsoft.com:443 HTTP/1.1
Proxy-Authorization: Negotiate TlRMT...=
Host: www.microsoft.com:443


Second reply



HTTP/1.1 200 Connection established
Connection: Keep-Alive
Proxy-Connection: Keep-Alive



Set KeepAlive to true and it works since the .NET client automaticlly makes two requests, just like .NET 2.0 does:


First request:



GET http://www.microsoft.com/en/us/default.aspx HTTP/1.1
Proxy-Authorization: Negotiate TlRMT...==
Host: www.microsoft.com


Reply



HTTP/1.1 407 Proxy Authentication Required ( Access is denied.  )
Proxy-Authenticate: Negotiate TlRMTV...=
Connection: Keep-Alive 


Automatic second request:



GET http://www.microsoft.com/en/us/default.aspx HTTP/1.1
Proxy-Authorization: Negotiate TlRMTV...=
Host: www.microsoft.com


Second reply



HTTP/1.1 200 OK
Connection: Keep-Alive

No comments:

Post a Comment