Solved

HTTPWebRequest returns "(407) Proxy Authentication Required" in  PreAuthenticate

Posted on 2011-03-25
3
3,313 Views
Last Modified: 2012-05-11
Hi All,
We have an already deployed .NET app that PreAuthenticates HttpWebRequest as below:
 
webRequest = (HttpWebRequest)HttpWebRequest.Create(address);
webRequest.Credentials = myCreds;
webRequest.PreAuthenticate = true;
webRequest.Method = "HEAD";
webRequest.Timeout = 10000;
webRequest.AllowWriteStreamBuffering = true;	
#region Proxy settings
WebProxy proxy = new WebProxy(proxyAddress, proxyPort);
proxy.Credentials = new NetworkCredential(cm.FirewallUser, cm.FirewallPassword);
webRequest.Proxy = proxy;
proxy.Credentials = NetworkCredential("domain\\user", "password")
webRequest.Proxy = proxy;
webResponse = (HttpWebResponse)webRequest.GetResponse();

Open in new window


as you can see I specify the proxy user as "domain\\user" since the proxy server does active directory authentication. However, preAuthentication fails with this error:

The remote server returned an error: (407) Proxy Authentication Required

I know the NetworkCredential(username, password, domain) constructor should be used to properly specify the domain name. But, the application is already deployed and I cannot make any changes to it. Does anyone know why supplying the domain name with the user name (i.e. domain\user) does not work? the customer reported that the username/password is not being supply to the proxy server which is strange since the application is setting the proxy credentials

any help?
0
Comment
Question by:hamid441
  • 3
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35220766
The constructor for NetworkCredential is overloaded to take three parameters:
new NetworkCredential("username", "password", "domain");

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35220768
Nevermind...   I missed that part in your post.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35220818
Looking at that assembly in Reflector, it appears as though username is, at some point, concatenated with the value of domain (separated by a \ ). Even if you were to leave the domain off, or set it to empty string, the "\" is still being inserted, so what you would end up with internally is something like:

    \username

which AD doesn't like.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question