验证用户用LDAP /网络凭证在.NET MVC [英] Validate User With LDAP/Network Credential in .NET MVC

查看:159
本文介绍了验证用户用LDAP /网络凭证在.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在.NET的MVC 3应用程序,我没有与LDAP太多的经验,但我希望能够用户是否存在简单地验证。我并不需要验证用户名和密码的组合,在本实施例

I'm working on an MVC 3 app in .NET, I don't have much experience with LDAP, but I wanted to be able to simply validate if a user exists. I don't need to validate the username and password combo as in this example:

在ASP.Net MVC LDAP验证

虽然这几乎是我想做的事情。我只需要确认他(她)在加入之前/用户名。

Although this is almost what I want to do. I just need to validate the username before he/she is added.

有一个简单的方法来做到这一点.NET / MVC

Is there a simple way to do this in .NET/MVC

推荐答案

使用 System.DirectoryServices.AccountManagement 命名空间,并通过在用户名或专有名称(例如:CN =李四)通过改变 IdentityType 枚举。

Use the System.DirectoryServices.AccountManagement namespace and pass in the username or distinguished name (e.g. CN=John Doe) by altering the IdentityType enum.

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; 
} 

这篇关于验证用户用LDAP /网络凭证在.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆