开发者

How to redirect route outside of a ASP.NET MVC3 controller in custom attribute?

开发者 https://www.devze.com 2023-03-27 21:22 出处:网络
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.

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);
    }
0

精彩评论

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