RedirectResult和RedirectToRouteResult在OnActionExecuting中不起作用

时间:2014-06-25 06:50:26

标签: asp.net-mvc session redirect actionfilterattribute onactionexecuting

RedirectResult和RedirectToRouteResult在OnActionExecuting内部无效,如果地址指定为localhost(/ Account / LogIn),如果我指定url为http://google.com正常工作。我为管理会话写了一个BaseConfig类。工作重定向时OnActionExecuting方法如果session为null,则登录url。我在项目中使用的BaseConfig类如下;

public class BaseConfig : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var context = HttpContext.Current;

        if (context.Session["loggedUser"] == null)
        {
            filterContext.HttpContext.Response.Redirect(FormsAuthentication.LoginUrl);

            //filterContext.Result = new RedirectToRouteResult(
            //new RouteValueDictionary { { "controller", "Account" }, { "action", "LogIn" } });
        }

        base.OnActionExecuting(filterContext);
    }
}

<authentication mode="Forms">
      <forms loginUrl="~/Account/LogIn" defaultUrl="~/Home/Index" timeout="2880" protection="All" slidingExpiration="true" path="/"/>
    </authentication>

0 个答案:

没有答案