存在显式转换(您是否错过了演员?)IPrincipal

时间:2018-01-05 07:32:53

标签: asp.net-mvc security

protected void Application_PostAuthenticateRequest()
{
    HttpCookie authoCookies = Request.Cookies[FormsAuthentication.FormsCookieName];
    if (authoCookies != null)
    {
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authoCookies.Value);
        JavaScriptSerializer js = new JavaScriptSerializer();
        User1 user = js.Deserialize<User1>(ticket.UserData);
        MyIdentity myIdentity = new MyIdentity(user);
        MyPrincipal myPrincipal = new MyPrincipal(myIdentity);
        HttpContext.Current.User = myPrincipal;  //here
    }
}

错误就在最后一行......

这是MyPrincipal课程。

public class MyPrincipal
{
    private readonly MyIdentity MyIdentity;
    public MyPrincipal(MyIdentity _myIdentity)
    {
        MyIdentity = _myIdentity;
    }
    public IIdentity Identity
    {
        get { return MyIdentity; }
    }

    public bool IsInRole(string role)
    {
        return Roles.IsUserInRole(role);
    }
}    

怎么办?我正在学习本教程

http://www.dotnetawesome.com/2015/06/part4-how-to-implement-custom-forms-authentication-in-aspnet-mvc.html

1 个答案:

答案 0 :(得分:1)

您的班级GRANT SELECT(id), INSERT(id) ON product TO editor_user; GRANT SELECT(mytext), UPDATE(mytext), INSERT(mytext), REFERENCES(mytext) ON product TO editor_user; 未能宣布已实施的界面MyPrincipal

IPricipal

C#中没有鸭子打字。