全名而不是User.Identity.Name域ID [英] Full name rather than the domain id in User.Identity.Name

查看:588
本文介绍了全名而不是User.Identity.Name域ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

User.Identity.Name 属性返回域登录ID。

The User.Identity.Name property returns the domain login id.

哪个类/属性公开实际的用户名?

Which class/property exposes the actual user name?

有关用户李四谁登录到Web应用程序提供my_domain \\ JDOE

For user "John Doe" who logs into the web application supplying my_domain\jdoe

**User.Identity.Name -** 
Returns : *my_domain\jdoe*

**System.Environment.UserName**
Returns: *jdoe*

哪个类/属性返回? ......李四

Which class/property returns? ... "John Doe"

推荐答案

如果你正在考虑的Active Directory,你需要找到对应于给定的samAccountName的UserPrincipal并从中获得DisplayName属性。请注意,它可能无法设置。

If you are thinking Active Directory, you'll need to find the UserPrincipal that corresponds to the given samAccountName and get the DisplayName property from it. Note that it may not be set.

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;
        }
    }
}

这篇关于全名而不是User.Identity.Name域ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆