HttpWebRequest + Windows Auth - NetworkCredential just doesn't work
From comment in linked duplicate question:
You need to specify the authentication type. When the server challenges the client with NTLM authentication the ICredentials.GetCredential method will be called on WebClient.Credentials with authType = "NTLM". If you used WebClient.Credential = new NetworkCredential(...) as no authentication type is specified the client won't be able to respond correctly. CredentialCache already implements this functionality. – Darin Dimitrov Nov 5 '09 at 14:57
Luke Puplett
Started out as a Windows PSS engineer for Microsoft UK, then built industrial scale automation solutions for banks before turning to application and systems programming on .NET and Azure.
Updated on April 12, 2021Comments
-
Luke Puplett about 3 years
I have an ASP.NET MVC 4 web service. On my dev box, I'm running IIS Express 7.5, so we're calling localhost:port. I have set it to use Windows Authentication and switched off Anonymous.
On my client, if I set
HttpWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials;
it works. But if I set the credentials to my other Windows domain account,
HttpWebRequest.Credentials = new NetworkCredential("lpuplett", "catsGoW00f", "ntdom"));
then I get a 401 Unauthorized. Am I misunderstanding something; should this work?
I've tried adding the credentials to a CredentialCache object and setting the cache.