在使用UserPrincipal.Current.ToString()获取域登录用户信息时,本地调试没有问题,上传到服务器报错
Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.
解决方法
将身份验证更改为“Windows身份验证”
-
换一种方法获取用户信息
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); UserPrincipal user = UserPrincipal.FindByIdentity(ctx, User.Identity.Name);
本文介绍在服务器上使用UserPrincipal.Current.ToString()时遇到的类型转换错误,并提供解决方案,包括更改身份验证设置和使用PrincipalContext及UserPrincipal类的替代方法。
23万+

被折叠的 条评论
为什么被折叠?



