Solved

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

Posted on 2011-03-25
3
3,283 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Getting hacked is no longer a matter or "if you get hacked" — the 2016 cyber threat landscape is now titled "when you get hacked." When it happens — will you be proactive, or reactive?
Cybersecurity has become the buzzword of recent years and years to come. The inventions of cloud infrastructure and the Internet of Things has made us question our online safety. Let us explore how cloud- enabled cybersecurity can help us with our b…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now