How to redirect route outside of a ASP.NET MVC3 controller in custom attribute?
I want to know how to redirect to a particular route from outside the controller. I have a custom attribute that I need to redirect the route in.
public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
// Want to redirect to route here.
base.OnAuthorization(开发者_如何学PythonfilterContext);
}
this should work
public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
// Want to redirect to route here.
filterContext.Result = new RedirectToRouteResult("routename", routeValues)
base.OnAuthorization(filterContext);
}
精彩评论