I am building my first website. I want it to use Windows Authentication. I would like to set the User's roles based on their group permissions. So, I want to get the group they belong to. But, I am having trouble figuring out how to find them in Active Directory. I am using System.DirectoryServices.
If I use the following
Hello, <asp:LoginName runat="server" />!
I get "Hello, DOMAIN\Username!" where DOMAIN\Username is the user's Windows login.
I want to use that information to get their Active Directory Display name, so I created a function in the code behind:
protected string DisplayName() { DirectoryEntry entry = new DirectoryEntry("LDAP://my.ldap.server/sAMAccountName=" + Page.User.Identity.Name); return entry.Name; }
I assumed that would get me something since the LoginName WebControl displays the Page.User.Identity.Name for the user.
Instead, it returns an empty string. I tried return Page.User.Identity.Name so that it would essentially do the same thing as the LoginName control, but that also returns the empty string. In other words, I have no idea how to get the logged in user so that I can do a search in AD. There is a wealth of knowledge in MSDN that gives me zero examples of this type of scenario. Essentially, it expects me to already know the user I want to look up, but does not tell me where that information is going to be stored.