无法在IIS 7上使用LdapConnection C#进行身份验证

时间:2016-05-04 09:59:19

标签: c# asp.net iis active-directory ldapconnection

我正在尝试使用Active Directory和C#进行身份验证。代码在Visual Studio 15下运行IIS Express,但是当我将项目部署到IIS服务器时,LDAP连接会返回以下错误:

  

"提供的凭证无效"

以下是我正在使用的代码:

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;
    }

当我使用Visual Studio进行调试时,一切正常,我可以验证并验证用户是否存在于AD服务器上,但是使用IIS服务器时会发生错误。

更新

我通过在IIS服务器上禁用域控制器来修复此问题。

1 个答案:

答案 0 :(得分:0)

我通过在IIS服务器上禁用域控制器来修复此问题。

相关问题