gpt4 book ai didi

c# - 如何在 ASP.NET Core 中获取 Active Directory 当前用户显示名称?

转载 作者:行者123 更新时间:2023-11-30 17:36:14 25 4
gpt4 key购买 nike

我正在使用 C# ASP.NET Core (MVC 6) 针对 on-prem Active Directory 设置。我可以简单地通过

获取当前用户的 用户名
public MyModel(IHttpContextAccessor httpContextAccessor)
{
string userName = httpContextAccessor.HttpContext.User.Identity.Name;
}

这给了我“DOMAIN\jsmith” 但是,我需要获取 Display Name,即“John Smith”。我该怎么做?

更新:经过更多挖掘,目前似乎不可用:https://github.com/dotnet/corefx/issues/2089

最佳答案

Novell ldap 库已ported .NET 核心。由于显示名称是 attribute你应该能够使用库来查询它(虽然没有具体的示例)

关于c# - 如何在 ASP.NET Core 中获取 Active Directory 当前用户显示名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39965898/

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