views:

369

answers:

1

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?

A: 

Use a 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
JP Alioto
Noooooes... but I don't wanna actually query AD!
Eric P