加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 19:46:03 所属栏目:百科 来源:网络整理
导读:我在MVC .Net 3.5中有一个网站,我需要在Controller中使用下面的代码. 所以我引用了名称空间 System.DirectoryServices.AccountManagement 我收到一个错误: Error 1 The type or namespace name 'DirectoryServices' does not exist in the namespace 'Syste
我在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读