locked
Is it possible to manage Active Directory Users Permissions on an Web application in c#? RRS feed

  • Question

  • I'm working with a web application developed in C #, who consumes and write Data to the MDS Web Service, but I need to have the possibility of select users from AD to assign permissions and Roles.

    Is it possible?

    If it is. Can you tell me the steps that I must to follow? Or at least whats topics I must to study to do this.

    Thank you in advance.
    Thursday, January 4, 2018 8:54 PM

Answers

  • Here is a sample code. It uses objects from System.DirectoryServices.AccountManagement namespace. There's quite a lot of other useful components inside System.DirectoryService namespace also.

    using (var ctx = new PrincipalContext(ContextType.Domain, "widgets.local")) { using (var search = new PrincipalSearcher(new UserPrincipal(ctx))) { foreach (var result in search.FindAll()) { DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry; Console.WriteLine("Given Name: " + de.Properties["givenName"].Value); Console.WriteLine("Last Name : " + de.Properties["sn"].Value); Console.WriteLine("SAM account name : " + de.Properties["samAccountName"].Value); Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value); Console.WriteLine(); } } } Console.ReadLine();

    • Marked as answer by PoorNavidad Tuesday, August 28, 2018 7:29 PM
    Friday, January 5, 2018 1:37 AM