在C#中获取用户名而不是域名\用户ID

问题描述 投票:0回答:2

我使用User.Identity.Name获取用户名。

但我没有用户名,而是获得域名\用户ID。

我正在使用Windows身份验证。

任何人都可以建议任何方式在Windows身份验证中获取用户名而不是用户ID。 C#。

谢谢....

c# asp.net windows-authentication
2个回答
0
投票

我认为您正在寻找用户显示名称。这是获得它的方法:

using System.DirectoryServices.AccountManagement;
var name = UserPrincipal.Current.DisplayName;

您需要添加对System.DirectoryServices.AccountManagement.dll的引用


-1
投票
logon_user = Request.ServerVariables["LOGON_USER"].Substring(// you domain length here);

例如:如果Domain长度为“8”字符,那么,

logon_user = Request.ServerVariables["LOGON_USER"].Substring(8);
© www.soinside.com 2019 - 2024. All rights reserved.