ASP.NET MVC 3 RedirectToRouteResult

时间:2012-11-20 00:40:49

标签: asp.net-mvc-3

RedirectToRouteResult不会重定向到指定的控制器 - 操作对。

public class CustAuthorizeAttribute : AuthorizeAttribute, IAuthorizationFilter
{
  ...
  public override void OnAuthorization(AuthorizationContext filterContext)
  {
     base.OnAuthorization(filterContext);
     ...
     if (...) {
        var routeDictionary = new RouteValueDictionary { { "action", "Forbidden" }, { "controller", "Error" } };
        filterContext.Result = new RedirectToRouteResult(routeDictionary);                    
     }
  }
}

请帮助。

1 个答案:

答案 0 :(得分:1)

也许你可以尝试类似的东西:

UrlHelper urlHelper = new UrlHelper(filterContext.HttpContext.Request.RequestContext);
filterContext.Result = urlHelper.Action("Forbidden" , "Error");