c# – 如何将PrincipalContext与MVC Web应用程序一起使用

我在MVC .Net 3.5中有一个网站,我需要在Controller中使用下面的代码.
所以我引用了名称空间

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

解决方法

确保已添加对此命名空间所在的System.DirectoryServices.AccountManagement.dll程序集的引用.

供参考:PrincipalContext.

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...