【发布时间】:2011-10-21 08:06:13
【问题描述】:
我在每个操作上使用 SessionExpireFilter 来检查会话是否已过期。如果会话已过期,则它将用户重定向到 sessionTimeoutPage 即到 membersController 和 SessionTimeOut 视图
过滤器看起来像-
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
/// <summary>
/// Called when [action executing].
/// </summary>
/// <param name="filterContext">The filter context.</param>
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))
{
if (ctx.Request.IsAuthenticated)
{
FormsAuthentication.SignOut();
}
//HttpCookie mycookie = new HttpCookie("ASP.NET_SessionId");
//mycookie.Expires = DateTime.MinValue;
//ctx.Response.Cookies.Add(mycookie);
//ctx.Session.Clear();
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("action", "SessionTimeOut");
redirectTargetDictionary.Add("controller", "Membership");
filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
}
}
base.OnActionExecuting(filterContext);
}
}
问题是我有一个会员控制器登录操作方法,它也有那个过滤器。它检查会话是否过期并总是找到 ASP.NET_SessionId cookie 并一次又一次地重定向到 sessionTimeout 页面(其中有一个登录页面的链接)
如果有人能提供帮助,那就太好了。
【问题讨论】:
标签: asp.net-mvc-3