How to wire common code from a base controller in ASP.NET MVC

前端 未结 3 1578
陌清茗
陌清茗 2021-01-05 09:23

My ASP.NET MVC application is a small part of a bigger ColdFusion app that is going to be soon replaced completely. I\'m passing some parameters from ColdFusion part through

3条回答
  •  一个人的身影
    2021-01-05 09:38

    If you already implemented a base controller just override its OnActionExecuting() method:

    public class YourBaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
    
            if(somethingIsWrong)
            {
                filterContext.Result = new RedirectToRouteResult(
                    new System.Web.Routing.RouteValueDictionary { ... });
            }
        }
    }
    

提交回复
热议问题