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

时间:2011-08-12 11:26:24

标签: c# asp.net asp.net-mvc asp.net-mvc-3 attributes

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

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

    base.OnAuthorization(filterContext);
}

1 个答案:

答案 0 :(得分: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);
    }