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
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
