Check UserID exists in Active Directory using C#(使用 C# 检查 Active Directory 中是否存在 UserID)
问题描述
我们如何检查 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C# 检查 Active Directory 中是否存在 UserID


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01