开发者

Response.Redirect not working inside an custom ActionFilter

My code is the following

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

        }
         base.OnActionExecuting(filterContext);
    }

}

Now, the question is WHY does the action that is has [SessionCheck] applied to it S开发者_运维问答TILL executes. Any ideas? Thanks.


Don't use Response.Redirect, rather replace the Result on the context with a RedirectResult. This will terminate processing in the filter chain and cause the redirect response to be sent immediately.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜