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
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
