HttpWebRequest + Windows Auth - NetworkCredential just doesn't work

I have an ASP.NET MVC 4 web service. In my dev block, I run IIS Express 7.5, so we call localhost: port. I installed it for Windows authentication and disabled Anonymous.

On my client, if I installed

HttpWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials; 

it works. But if I set the credentials for my other Windows domain account,

 HttpWebRequest.Credentials = new NetworkCredential("lpuplett", "catsGoW00f", "ntdom")); 

then i get 401 unauthorized. I misunderstand something; if it works?

I tried adding credentials to the CredentialCache object and setting the cache at the intersection of the fingers, as well as with my eyes closed, really hopeful.

Thanks,

Luke

solvable

It worked for 3 hours of searching and after publishing my own question I landed on the answer, here on trusty SO:

Domain credentials for WebClient class not working

Thanks for this; -)

+6
source share
1 answer

From a comment in a related duplicate question:

You need to specify the type of authentication. When the server issues NTLM authentication to the client, the ICredentials.GetCredential method will call WebClient.Credentials with authType = "NTLM". If you used WebClient.Credential = the new NetworkCredential (...) as the lack of authentication type specified, the client will not be able to respond correctly. CredentialCache already implements this functionality. - Darin Dimitrov

Dimitrov
+5
source

Source: https://habr.com/ru/post/921196/


All Articles