MVC actionfilter属性重定向循环

时间:2014-12-13 05:27:54

标签: asp.net-mvc-5 action-filter actionfilterattribute custom-action-filter

我正在创建一个actionfilter来检查用户会话,但是当我运行网页时显示以下消息

This webpage has a redirect loop

这是代码

public class CustomActionFilter : ActionFilterAttribute, IActionFilter
    {
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Session["authenticate"] == null)
            {
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Account" }, { "action", "Login" } });
            }
            base.OnActionExecuting(filterContext);
        }
    }

控制器代码

public class AdminController : Controller
    {
        //
        // GET: /Admin/
       [CustomActionFilter]
        public ActionResult Index()
        {
            return View();
        }
}

一次又一次地调用此函数

注意:我是actionfilters

的新手

0 个答案:

没有答案