我使用User.Identity.Name
获取用户名。
但我没有用户名,而是获得域名\用户ID。
我正在使用Windows身份验证。
任何人都可以建议任何方式在Windows身份验证中获取用户名而不是用户ID。 C#。
谢谢....
我认为您正在寻找用户显示名称。这是获得它的方法:
using System.DirectoryServices.AccountManagement;
var name = UserPrincipal.Current.DisplayName;
您需要添加对System.DirectoryServices.AccountManagement.dll
的引用
logon_user = Request.ServerVariables["LOGON_USER"].Substring(// you domain length here);
例如:如果Domain长度为“8”字符,那么,
logon_user = Request.ServerVariables["LOGON_USER"].Substring(8);