设置(使用 MVC 4)
public class MyAuthorizeAttribute : AuthorizeAttribute {
protected override bool AuthorizeCore(HttpContextBase httpContext) {
var isAuthorised = base.AuthorizeCore(httpContext);
if(isAuthorised) {
// retrieve authentication ticket from cookie and
// create custome principal and attach to
// httpContext.User
}
return isAuthorised;
}
}
Gloabl.asax.cs:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new MyAuthorizeAttribute());
}
HomeController.cs:
using System.Web.Mvc;
public class HomeController : Controller
{
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
}
问题
调用主页会强制加载登录页面。
问题
当 HomeController.Index() 动作用 [AllowAnonymous] 修饰时,为什么 ASP 将我重定向到登录视图?
我正在使用这篇文章作为参考