我有一個Web應用程序,剛剛開始隨機丟失會話。確切的原因至多是難以捉摸的,但是看起來會話在服務器端被殺死/丟失,並且導致用戶需要完全關閉瀏覽器並重新啓動才能重新登錄。ASP.NET MVC Web應用程序 - 會話隨機失敗
我希望我可以提供一些代碼,但我無法弄清楚問題出在哪裏。
這裏是一個會話行爲過濾我們目前使用的:
public class SessionExpireAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext lvContext = HttpContext.Current;
//if(
// check if session is supported
if (lvContext.Session != null)
{
// check if a new session id was generated
if (lvContext.Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = lvContext.Request.Headers["Cookie"];
if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
{
lvContext.Response.Redirect("~/Account/Timeout");
}
}
}
base.OnActionExecuting(filterContext);
}
}
AFAIK它的唯一文件夾刪除,導致此,添加和刪除文件應該沒問題,除非你從/ bin和/ App_Data文件夾中添加和刪除它們。此外,通過編程方式修改Web.config文件可能會導致App Domain重新啓動。檢查你的代碼是不是在任何地方做這些事情。如果刪除文件夾是一個問題,請告訴我,我知道解決辦法。 – 2010-06-29 08:42:11
我最近添加了兩個基於Web的圖像編輯器,但它們只添加/刪除臨時tiff文件。除非我們發佈新版本,否則Web.config永遠不會以編程方式或手動方式更改。 – alan 2010-06-29 13:13:28
臨時解決方案是每100次調用後回收App Pool。這大大降低了我們的事故率。 – alan 2010-08-17 16:13:38