我们如何检查 USERID 是否存在于 Active Directory 中.
How can we check whether the USERID exists in Active Directory or not.
我有 LDAP 字符串和用户 ID,我可以找到该用户 ID 是否存在于 Active Directory 中.我将此用于 ASP.NET Web 应用程序 (.NET 3.5)
I have LDAP String and UserID, can I find whether that UserID exists in Active Directory or not. I am using this for ASP.NET Web Application (.NET 3.5)
您可以执行以下操作(将域替换为您正在验证的域或完全删除参数):
You can do something along the lines of (replacing domain with the domain you're authenticating against or removing the parameter altogether):
public bool DoesUserExist(string userName)
{
using (var domainContext = new PrincipalContext(ContextType.Domain, "DOMAIN"))
{
using (var foundUser = UserPrincipal.FindByIdentity(domainContext, IdentityType.SamAccountName, userName))
{
return foundUser != null;
}
}
}
实现检查用户是否存在.这来自 System.DirectoryServices.AccountManagement
命名空间和程序集.
To achieve checking for if a user exists. This comes from the System.DirectoryServices.AccountManagement
namespace and assembly.
您可以在 http://msdn 上找到更多信息.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx
您可能希望更多地了解 PrincipalContext,因为它具有用于验证用户凭据等的有趣方法.
You may want to check more into PrincipalContext as it has interesting methods for authenticating user credentials and such.
这篇关于使用 C# 检查 Active Directory 中是否存在 UserID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!