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

c# – 无法在System.DirectoryServices.AccountManagement.Group

发布时间:2020-12-15 06:51:00 所属栏目:百科 来源:网络整理
导读:我使用方法UserPrincipal.Current.ToString()在域中获取当前登录域用户与有效域.但是当我在一个字符串中显示它时,它在IIS服务器中托管时出现错误: Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'Sy
我使用方法UserPrincipal.Current.ToString()在域中获取当前登录域用户与有效域.但是当我在一个字符串中显示它时,它在IIS服务器中托管时出现错误:
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal'
           to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.

解决方法

我有同样的问题.它在我的本地机器上完美工作,但在服务器上部署到IIS时失败.最后我不得不改变两件事情来使它工作:

>将验证更改为“Windows身份验证”(how-to)
>而不是使用当前,分两步做:(source)

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

X-4545 X-4545 X-4545 X-4545 X- 20045 X-4545 X- 20045 X- 20045 X- 20045 X-4545

最后得到这个名字(或任何其他信息),我使用了user.DisplayName.

(编辑:李大同)

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

    推荐文章
      热点阅读