开发者

ASP.NET MVC Web App - Session Randomly Fails

开发者 https://www.devze.com 2023-01-04 20:47 出处:网络
I\'ve a Web App that just recently has began randomly losing sessions.The exact cause is elusive at best, however it seems the session is killed/lost on the server side and results in the user needing

I've a Web App that just recently has began randomly losing sessions. The exact cause is elusive at best, however it seems the session is killed/lost on the server side and results in the user needing to close their browser entirely and relaunch in order to log back in.

I wish I could provide some code, but I can't figure out where the problem is at all.

Here is a session action filter we use currently:

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 sa开发者_开发问答ys 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);
    }
}


Did you add a new feature that adds or removes files from the root directory or any of its subdirectories? That can cause the session to reset.


Ultimately I moved to SQL State Server to handle my sessions. This outsources session handling to the SQL server allowing a session to persist through a recycle, etc. For more information see these links:

  • Session-State Modes
  • HOW TO: Configure SQL Server to Store ASP.NET Session State
0

精彩评论

暂无评论...
验证码 换一张
取 消