【发布时间】:2016-08-29 16:40:38
【问题描述】:
我正在尝试使用活动目录和 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 服务器上的域控制器解决了这个问题。
【问题讨论】:
-
服务器是否加入了与您的开发机器不同的域?
-
不..他们在同一个域中
-
尝试将
AuthType设置为AuthType.Ntlm。如果这有效,则表明存在 Kerberos 问题。 -
试过了,但没有运气:\
-
你应该检查这个topic关于凭证验证,并使用
PrincipalContext.ValidateCredentials方法。它更有效。
标签: c# asp.net iis active-directory ldapconnection