我正在尝试使用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服务器上禁用域控制器来修复此问题。
答案 0 :(得分:0)
我通过在IIS服务器上禁用域控制器来修复此问题。