从Windows身份验证在ASP.Net BLL类获取全名 [英] Get Full name from Windows Authentication in ASP.Net BLL class

查看:160
本文介绍了从Windows身份验证在ASP.Net BLL类获取全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图找出如何获取当前用户的全名,如在我的ASP.Net应用程序在Active Directory中输入从BLL类。到目前为止,我有:

Trying to figure out how to get the current User's Full Name as entered in Active Directory from a BLL class in my ASP.Net application. So far I have:

   public static string Username
    {
        get
        {
            var name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

            if (name.Contains("\\"))
            {
                var start = name.IndexOf("\\");

                if (name.Length > start)
                {
                    name = name.Substring(start + 1);
                }
            }

            return name;
        }
    }

这样做的问题是,这将返回用户名,但我也需要全名的。任何人都知道这是可能的?

The problem with this is that this will return the Username, but I am also in need of the Full Name. Anyone know if this is possible?

推荐答案

使用的的DirectorySearcher ...

var search = new DirectorySearcher( new DirectoryEntry("LDAP://YourDomain") );
search.Filter = "(sAMAccountName=UserNameHere)"; // put the identity name here
var res  = search.FindOne();
var name = res["displayName"]; // I believe this is the right property

这篇关于从Windows身份验证在ASP.Net BLL类获取全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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