Since you are using .NET 3.5 and above, you should check the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read more here:
Basically, you can define the context of a domain and easily find users and / or groups in AD:
// set up domain context using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain)) { // find a user UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName"); if(user != null) { // do something here.... string homeDrive = user.HomeDrive; string homeDirectory = user.HomeDirectory; } }
If you use Windows authentication in your ASP.NET MVC application, you can also get a registered user at the moment:
UserPrincipal currentUser = UserPrincipal.Current;
But most often in a web application it is something like the NETWORK SERVICE or IUSER_machineName user (and not your user in the browser) ...
The new S.DS.AM makes it very easy to play with users and groups in AD!
source share