The User.Identity.Name
属性返回域登录 ID。
哪个类/属性公开了实际的用户名?
对于登录到提供 my_domain\jdoe 的 Web 应用程序的用户“John Doe”
**User.Identity.Name -**
Returns : *my_domain\jdoe*
**System.Environment.UserName**
Returns: *jdoe*
返回哪个类/属性? ...“约翰·多伊”
如果您考虑的是 Active Directory,则需要找到与给定 samAccountName 对应的 UserPrincipal 并从中获取 DisplayName 属性。请注意,它可能未设置。
string fullName = null;
using (PrincipalContext context = new PrincipalContext( ContextType.Domain ))
{
using (UserPrincipal user
= UserPrincipal.FindByIdentity( context,
User.Identity.Name ))
{
if (user != null)
{
fullName = user.DisplayName;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)