7

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.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
  • I guess this is not duplicate. I pointed posts asks for windows authentication and the answer in that post uses Ntlm… I am also facing same issue using windows authentication – Ziggler Feb 07 '19 at 18:41

1 Answers1

5

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
  • 42,091
  • 47
  • 181
  • 266