2012-10-15 83 views
2

我在MVC .Net 3.5中有一个网站,我需要在控制器中使用下面的代码。 所以我引用名字空间如何在MVC Web应用程序中使用PrincipalContext

System.DirectoryServices.AccountManagement

我收到一个错误:

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

哪些组件我失去了以及如何将其在项目中添加?

 // 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; 
     } 

回答

14

确保您已经添加参考System.DirectoryServices.AccountManagement.dll组件,该组件是这个命名空间住在哪里。

仅供参考:PrincipalContext

+1

感谢达林,我能够使用项目参考添加dll。非常感谢 – GibboK

相关问题