0
當會話過期時,我想重定向用戶回到登錄頁面。所以我添加了一個類並從ActionFilterAttribute繼承,所以我可以隨時檢查一個動作即將被執行。作爲一個測試,我把這個代碼:重新路由到使用RouteValueDictionary視圖導致許多重定向... MVC3
public class SessionFilters : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var defaults = new RouteValueDictionary {{"Controller", "Home"}, {"Action", "About"}};
filterContext.Result = new RedirectToRouteResult(defaults);
base.OnActionExecuting(filterContext);
}
}
正如你所看到的,我強制重定向到About視圖,但我得到下面的錯誤在我的瀏覽器:
The webpage at http://localhost:58494/Home/About has resulted in too many redirects.
Clearing your cookies for this site or allowing third-party cookies may fix the
problem. If not, it is possibly a server configuration issue and
not a problem with your computer.
如何我是否正確地重定向到使用此方法的另一個視圖?謝謝
UPDATE沒關係。我有一個荷馬辛普森時刻。我所定義的是一個無限循環,所以瀏覽器就像「忘記了這一點」。代碼正在工作..