在.NET MVC中使用LDAP /网络凭据验证用户

3 c# validation ldap asp.net-mvc-3

我正在使用.NET中的MVC 3应用程序,我对LDAP没有太多经验,但我希望能够简单地验证用户是否存在.我不需要验证用户名和密码组合,如下例所示:

ASP.Net MVC中的LDAP身份验证

虽然这几乎是我想要做的.我只需要在添加用户名之前验证用户名.

有没有一种简单的方法在.NET/MVC中执行此操作

Nic*_*ick 5

使用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)