Search code examples
c#asp.netiisactive-directoryldapconnection

Unable to authenticate with LdapConnection C# on IIS 7


I am trying to authenticate using active directory and C#. The code is working on IIS Express under Visual Studio 15 but when I deploy my project to an IIS server, the LDAP connection returns the following error :

"The Supplied Credential is invalid"

Here is the code I am using:

public static dynamic AuthenticationUser(string username, string password)
{
    bool validation;
    try
    {
        var credentials = new NetworkCredential(username, password, "somedomain");
        var serverId = new LdapDirectoryIdentifier("someserver");
        LdapConnection conn = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));

        conn.Credential = credentials;
        conn.AuthType = AuthType.Negotiate;
        conn.Bind(credentials);
        validation = true;
    }
    catch (LdapException ex)
    {
        validation = false;
        return ex.Message;
    }

Everything is OK when I debug with Visual Studio, I can verify and validate that the user exists on the AD server, but with IIS server the error occurs.

Update

I fixed this issue by disabling the domain controller on the IIS server.


Solution

  • I fixed this issue by disabling the domain controller on the IIS server.