美文网首页
Unable to cast object of type in

Unable to cast object of type in

作者: 菜鸟飞不动 | 来源:发表于2019-02-27 15:51 被阅读0次

在使用UserPrincipal.Current.ToString()获取域登录用户信息时,本地调试没有问题,上传到服务器报错

Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.

解决方法

  1. 将身份验证更改为“Windows身份验证”

  2. 换一种方法获取用户信息

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, User.Identity.Name);
    

相关文章

网友评论

      本文标题:Unable to cast object of type in

      本文链接:https://www.haomeiwen.com/subject/wksfuqtx.html