Solved

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

Posted on 2011-03-25
3
3,375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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