当会话过期时,我想将用户重定向回登录页面。所以我添加了一个类并从 ActionFilterAttribute 继承,所以我可以随时检查即将执行的操作。作为测试,我将此代码放入:
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.
如何使用此方法正确重定向到另一个视图?谢谢
更新没关系。我有一个荷马辛普森时刻。我定义的是一个无限循环,所以浏览器就像“忘记这个”。代码正在运行..