【问题标题】:Response.Redirect not working inside an custom ActionFilterResponse.Redirect 在自定义 ActionFilter 中不起作用
【发布时间】:2010-05-04 12:17:15
【问题描述】:

我的代码如下

public class SessionCheckAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        if (/*condition*/)
        {
            filterContext.HttpContext.Response.Redirect("http://www.someurl.com",true);

        }
         base.OnActionExecuting(filterContext);
    }

}

现在,问题是为什么应用了 [SessionCheck] 的操作仍然执行。有任何想法吗?谢谢。

【问题讨论】:

  • 是否也应该将其标记为 ASP.NET MVC?

标签: asp.net-mvc redirect action-filter


【解决方案1】:

不要使用 Response.Redirect,而是用 RedirectResult 替换上下文中的 Result。这将终止过滤器链中的处理并立即发送重定向响应。

filterContext.Result = new RedirectResult( "http://www.someurl.com" );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-27
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多