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

Die*_*xel 0 c# asp.net asp.net-mvc attributes asp.net-mvc-3

我想知道如何从控制器外部重定向到特定路由.我有一个自定义属性,我需要重定向路由.

public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
    // Want to redirect to route here.

    base.OnAuthorization(filterContext);
}
Run Code Online (Sandbox Code Playgroud)

sta*_*k72 6

这应该工作

public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
    {
        // Want to redirect to route here.
        filterContext.Result = new RedirectToRouteResult("routename", routeValues)

        base.OnAuthorization(filterContext);
    }
Run Code Online (Sandbox Code Playgroud)