我正在 .NET 中开发 MVC 3 应用程序,我对 LDAP 没有太多经验,但我希望能够简单地验证用户是否存在。我不需要像本例中那样验证用户名和密码组合:
LDAP Authentication in ASP.Net MVC
虽然这几乎就是我想做的。我只需要在添加他/她之前验证用户名。
在 .NET/MVC 中是否有一种简单的方法可以做到这一点
最佳答案
使用 System.DirectoryServices.AccountManagement
命名空间并通过更改 IdentityType
枚举传入用户名或专有名称(例如 CN=John Doe)。
public bool UserExists(string username)
{
PrincipalContext domain = new PrincipalContext(ContextType.Domain);
// locate the user
UserPrincipal user = UserPrincipal.FindByIdentity(domain, IdentityType.Name, username);
return user != null;
}
关于c# - 在 .NET MVC 中使用 LDAP/网络凭据验证用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8895562/