2

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

请帮忙。

4

1 回答 1

1

也许您可以尝试以下方法:

UrlHelper urlHelper = new UrlHelper(filterContext.HttpContext.Request.RequestContext);
filterContext.Result = urlHelper.Action("Forbidden" , "Error"); 
于 2012-11-20T01:25:05.257 回答