简体   繁体   English

如何在自定义属性中重定向 ASP.NET MVC3 controller 之外的路由?

[英]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.我想知道如何从 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(filterContext);
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM