2012-11-20 148 views
2

RedirectToRouteResult不會重定向到指定的控制器 - 操作對。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);      
    } 
    } 
} 

請幫忙。

+0

它的路線哪裏來?你有什麼特別的路線設置?你的路由規則是什麼樣的? – dreza

回答

1

或許你可以嘗試像:

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