【发布时间】:2011-03-21 17:14:11
【问题描述】:
我有一个客户过滤器属性来检查我的 .Net MVC 应用程序中的过期会话,该应用程序在标准 html 表单上运行良好。但是,当我将该属性应用于由 Ajax 表单调用的操作并且会话已过期时,它会将登录页面(过滤器属性重定向上下文的位置)重新加载到 ajax 更新容器中。如果在进行 ajax 调用时会话过期,是否有人知道如何让整个页面重定向到登录页面,或者有人知道如何更优雅地处理这种情况?提前致谢。
public class SessionExpiredFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check if session is supported
if (ctx.Session != null)
{
// check if a new session id was generated
if (ctx.Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = ctx.Request.Headers["Cookie"];
if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
{
//SessionHelper.AddPageMessage("message", "Your session has expired. Please login to continue");
ctx.Response.Redirect("~/Account/Logon");
}
}
}
base.OnActionExecuting(filterContext);
}
}
【问题讨论】:
-
我自己也在寻找答案。
标签: .net ajax model-view-controller session