gpt4 book ai didi

c# - 我可以从 WindowsPrincipal 获取 Active Directory 属性吗?

转载 作者:太空狗 更新时间:2023-10-29 23:19:07 25 4
gpt4 key购买 nike

我想获取当前登录用户的员工 ID。这在某些 .Net 类中是否很容易获得,或者我是否需要执行某种 LDAP 查询?

欢迎任何提示

最佳答案

更简单 - 使用新的 .NET 3.5 System.DirectoryServices.AccountManagement 功能。

请参阅 MSDN 文章 Managing Directory Security Principals in the .NET Framework 3.5了解详情。

PrincipalContext ctx = new PrincipalContext(ContextType.Domain. "YOURDOMAIN");

UserPrincipal user = UserPrincipal.FindByIdentity(ctx, loginName);

if(user != null)
{
string empID = user.EmployeeId;
}

新的强类型主体类使使用 AD 变得轻而易举。

关于c# - 我可以从 WindowsPrincipal 获取 Active Directory 属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2808955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com