首页 > 其他分享 >Unable to cast object of type in System.DirectoryServices.AccountManagement.GroupPrincipal

Unable to cast object of type in System.DirectoryServices.AccountManagement.GroupPrincipal

时间:2023-03-22 12:02:20浏览次数:48  
标签:GroupPrincipal object System 身份验证 UserPrincipal DirectoryServices type AccountMa


在使用​​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);

标签:GroupPrincipal,object,System,身份验证,UserPrincipal,DirectoryServices,type,AccountMa
From: https://blog.51cto.com/dupeng0811/6142368

相关文章