如何从基本控制器OnActionExecuting重定向? [英] How to redirect from OnActionExecuting in Base Controller?

查看:312
本文介绍了如何从基本控制器OnActionExecuting重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了两种方式:Response.Redirect的(),它什么都不做,以及调用基控制器,它返回一个ActionResult,并使其返回RedirectToAction(里面的新方法)......这些都不工作<。 / p>

我怎样才能从OnActionExecuting方法做一个重定向?


解决方案

 公共覆盖无效OnActionExecuting(ActionExecutingContext filterContext)
 {
    ...
    如果(needToRedirect)
    {
       ...
       filterContext.Result =新RedirectResult(URL);
       返回;
    }
    ...
 }

I have tried two ways: Response.Redirect() which does nothing, as well as calling a new method inside of the Base Controller that returns an ActionResult and have it return RedirectToAction()... neither of these work.

How can I do a redirect from the OnActionExecuting method?

解决方案

 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
    ...
    if (needToRedirect)
    {
       ...
       filterContext.Result = new RedirectResult(url);
       return;
    }
    ...
 }

这篇关于如何从基本控制器OnActionExecuting重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆