-1
嗨我有一些ASP.NET MVC會話狀態的問題,在我實現下面的代碼段並將屬性放在方法上之後沒有過期。ASP.NET MVC中的會話過期問題
public sealed class SessionActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
//Check if session is supported
if (ctx.Session != null)
{
//Check if the session is new
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 = filterContext.HttpContext.Request.Headers["Cookie"];
if ((sessionCookie != null) && (sessionCookie.IndexOf("ASP.NET_SessionId", StringComparison.OrdinalIgnoreCase) >= 0))
{
//Redirect to the login page
ctx.Response.Redirect("~/Home/Index", true);
ctx.Response.End();
}
}
}
base.OnActionExecuting(filterContext);
}
}
問題是重定向請求未執行,並且執行了具有SessionActionFilter屬性的Action。此方法使用已過期並導致錯誤的會話變量。
有人可以告訴我缺少什麼嗎?
非常感謝!
我很好奇你使用會話的是什麼? – 2010-06-16 06:47:42