Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest + Windows Auth - NetworkCredential just doesn't work [duplicate]

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.

like image 500
Luke Puplett Avatar asked Jul 24 '12 11:07

Luke Puplett


1 Answers

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

like image 105
Luke Puplett Avatar answered Sep 28 '22 21:09

Luke Puplett