Unable to cast object of type 'System.Web.Security.RoleP

本文关键字:System Web Security RoleP cast to object of type Unable | 更新日期: 2023-09-27 18:09:36

我想从这个RolePrincipal转换到我的customPrincipal,但我得到这个错误,这是我的代码。

var identity = ((CustomPrincipal)HttpContext.Current.User).CustomIdentity;

Unable to cast object of type 'System.Web.Security.RoleP

这是因为你的CustomPrincipal既不是HttpContext.Current.User的类型,也不是它的基类型。