0

I am trying to validate credential for principal context using below code. But it is giving error "the server cannot handle directory requests".

principalContext.ValidateCredentials("Username", "Password");

After doing some internet search I came to know that I need to pass another parameter ContextOptions to make it work.

I found this link to resolve issue

.Net's Directory Services throws a strange exception

principalContext.ValidateCredentials("Username", "Password", ContextOptions.Negotiate);

It is working. But I cannot understand the root cause. If anyone can explain it in detail then it will be very helpful.

Community
  • 1
  • 1
Bhargav
  • 1
  • 2

1 Answers1

-1

From what you described here, outcome should really depend on your AD environment.

Negotiate - The client is authenticated by using either Kerberos or NTLM. When the user name and password are not provided, the Account Management API binds to the object by using the security context of the calling thread, which is either the security context of the user account under which the application is running or of the client user account that the calling thread represents.

You can see the definition of ContextOptions from here:

https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.contextoptions(v=vs.110).aspx

wannadream
  • 1,669
  • 1
  • 12
  • 14
  • 1
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – FelixSFD Feb 28 '17 at 20:53
  • But I'm providing username and password! Still I have to pass context option, that's what I cannot understand. – Bhargav May 16 '17 at 08:51
  • The parameter is optional. It has another method without ContextOptions. https://msdn.microsoft.com/en-us/library/bb154889(v=vs.110).aspx – wannadream May 16 '17 at 16:14