How to get AD properties for user of web browser

Viewed 223

This code gets me properties of an AD user in our organization, specifically the user that the web site is running as, a service account (so the results are the same no matter what user is running the web site):

DirectoryEntry entry = UserPrincipal.Current.GetUnderlyingObject() as DirectoryEntry;
if (entry != null)
{
    foreach (string name in entry.Properties.PropertyNames)
    {
        Response.Write(entry.Properties[name].Value.ToString() + "</br>");
    }
}

However, what I need is to get those properties for the user who is running the web browser. I would think I could get those from HttpContext, but can't find that principal or a GetUnderlyingObject() method that way.

How do I get that same list of AD properties for the user who is logged into the Windows machine and running the web browser?

1 Answers

string user = HttpContext.Current.User.Identity.Name.ToString();

You should be able to find more info on using AD in webforms via google search, if you need to do something more with that info other than print it :)

Related