I know this has been asked many many times. I have read most all posts on here and other sites like this one.
http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/2931d21c-9ca8-4256-b213-915fad4c941b/
With no avail. Here's the environment
Windows Server 2008 R2 64bit Visual Studio 2008 .Net Framework 3.5
Here is what I have tried
I had the proxy authenticating using code
WebRequest req = WebRequest.Create(requestUri + data);
req.Proxy = new System.Net.WebProxy(<ProxyURL>:<port>",true);
req.Proxy.Credentials = CredentialCache.DefaultCredentials;
WebResponse resp = req.GetResponse();
This worked, but seeing as it was slowing down the app I learned that I can edit the machine.config file which I did. It worked too!
<system.net>
<defaultProxy
useDefaultCredentials="true">
<proxy
proxyaddress="<proxyURL>:<port>"
bypassonlocal="True"/>
</defaultProxy>
</system.net>
At least for a day or 2. Then it began failing.
I then edited it to this
<system.net>
<defaultProxy
useDefaultCredentials="true">
<proxy usesystemdefault="True"/>
</defaultProxy>
</system.net>
From my understanding this will use IE settings to connect to proxy but still does not work. I also tried tihs code
WebProxy proxy = new WebProxy(<proxy>:<port>);
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(requestUri + data), "BASIC", new NetworkCredential(<username>,<password>));
proxy.Credentials = myCache;
request.Proxy = proxy;
request.Method = "GET";
And this did not work.
Note: I can copy the machine.config file to my computer(Win XP) and run the .exe(without the proxy code) from there and it works fine.
Is there something different I need to do with a 64 bit OS? Also I can open IE8 on the server and access the URI just fine. the goal is to preauthenticate the proxy without having to supply a username password in the code.
HttpWebRequest uses the default Internet Settings (IE) proxy anyway, so if it works fine from Internet Explorer on the server, it should be ok from your code as well (provided it's running under the same user account).
I would put machine.config back as it was.
One thing I would check would be in IIS, is you can configure the Providers for the Windows Authentication applet. This should list NTLM and Kerberos as the providers in a list; I would switch them around and see if that makes a difference (e.g. if NTLM is top of the list, move Kerberos to the top). I'm sorry I can't give you the exact instructions as I don't have IIS on this machine.
If you're still struggling, I would recommend you run Fiddler on the server to capture the request and response flow for more clues.