我想自定义MVC 3.在家里控制器我设置的作用是在authorize ...定制授权MVC3错误
Session["role"] = "Admin";
我收到错误的
SiteRoles role = (SiteRoles)httpContext.Session["role"];
说明指定的转换无效。
我没有线索发生了什么。
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
string[] users = Users.Split(',');
if (!httpContext.User.Identity.IsAuthenticated)
return false;
string role = (string)httpContext.Session["role"];
if (Roles != 0 && ((Roles & role) != role))
return false;
return true;
}
我也是以下示例在... http://mvchosting.asphostcentral.com/post/ASPNET-MVC-Hosting-Working-with-Custom-Authorisation-in-ASPNET-MVC-Framework.aspx – Beginner