none
Error in PrincipalContext.ValidateCredentials RRS feed

  • Question

  • I have used below code to authenticate user with Active Directory.

    using (PrincipalContext principalContext1 = new PrincipalContext(ContextType.Domain, domainName))
    {
        if (principalContext1.ValidateCredentials(userName, password))
        {
             //code to successful login
        }
    }
    

    Getting error "The server cannot handle directory requests." in ValidateCredentials method. I have tried passing contextOptions as third parameter "ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing". It resolved my error, but I came to know from msdn that it is default parameter. Why should I need to pass this? Any alternative solutions? Thanks in advance.

    Monday, February 19, 2018 11:56 AM

All replies

  • Hi Savan savani,

    Thank you for posting here.

    For your question, I test the code you provided with my own domain name, userName, passWord. There is no error.

    According to your description, the parameter you set is a default option value. It is declared in MSDN article.

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

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, February 21, 2018 7:47 AM
    Moderator
  • Hi Wendy. 

    Thanks for reply. I am using windows service for authentication. Service is running with local system user. Whenever I try running my service with other user(identity user) it works fine. Is there any issue with service with local user and my code?

    Monday, February 26, 2018 7:06 AM
  • Hi Savan savani,

    I test your code with my local user. It works well on my side. 

    Does your local user and the other user in same domain? Do these accounts has the same permission? Try to run as admin to run your service with local account.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 1, 2018 2:02 AM
    Moderator