我正在尝试在MVC5应用程序中实现自定义主体。首先,我试图实现IPrincipal并覆盖基础WebViewPage。但是,从customPrincipal转换为无效。我得到了:
无法将“System.Security.Principal.WindowsPrincipal”类型的对象强制转换为类型 CustomPrincipal
我无法理解为什么在我实现customPrincipal中需要的所有内容之前,为什么这不会投射并且想要确保至少这个有效。为什么这不能投?
public abstract class CustomWebViewPage : WebViewPage
{
public virtual new CustomPrincipal User { get { return (CustomPrincipal)base.User; } }
}
public abstract class CustomWebViewPage<TModel> : WebViewPage<TModel>
{
public virtual new CustomPrincipal User { get { return (CustomPrincipal)base.User; } }
}
public class CustomPrincipal : IPrincipal
{
public bool IsInRole(string role)
{
throw new NotImplementedException();
}
public IIdentity Identity { get; private set; }
}