Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PrincipalContext with MVC Web Application

I have a website in MVC .Net 3.5, I need to use the code below in a Controller. So I'm referencing the name space

System.DirectoryServices.AccountManagement

And I receive an error:

Error   1   The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?)

Which assembly Am I missing and how to add it in the project?

        // set up domain context
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

        // find a user
        UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

        if (user != null)
        {
            // do something here.... 
            string givenName = user.GivenName;
        }
like image 533
GibboK Avatar asked Oct 15 '12 06:10

GibboK


1 Answers

Make sure you have added reference to the System.DirectoryServices.AccountManagement.dll assembly which is where this namespace lives.

For reference: PrincipalContext.

like image 193
Darin Dimitrov Avatar answered Oct 02 '22 17:10

Darin Dimitrov