I recently started a project where I have to authenticate users against the Active Directory.
Using authentication mode=”Windows”. I managed to login and retrieve the user name.
@Context.User.Identity.Name
Now I was wondering how I could get the GUID from the user that is logged in.
I want to use the GUID from the active directory in my own database to make its members unique.
Since you’re on .NET 3.5 and up, you should check out the
System.DirectoryServices.AccountManagement(S.DS.AM) namespace. Read all about it here:Basically, you can define a domain context and easily find users and/or groups in AD:
The new S.DS.AM makes it really easy to play around with users and groups in AD: