3 c# validation ldap asp.net-mvc-3
我正在使用.NET中的MVC 3应用程序,我对LDAP没有太多经验,但我希望能够简单地验证用户是否存在.我不需要验证用户名和密码组合,如下例所示:
虽然这几乎是我想要做的.我只需要在添加用户名之前验证用户名.
有没有一种简单的方法在.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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7594 次 |
| 最近记录: |