ASP.NET MVC 4 sessions expiring after 10 minutes on Windows Azure

I am currently creating a website using ASP.net and MVC4. When debugging locally, sessions work as expected without any problem and expire 1 day after they are logged in. However, on real site sessions, it expires every 10 minutes and becomes annoying.

Here is the web config

<sessionState timeout="1440" cookieless="false"></sessionState>

      

and

 <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="1440"/>      
    </authentication>

      

Here is the login method from the controller.

public ActionResult LogIn(UserModel user)
    {
        var response = new RegistrationResponse();

        if (ModelState.IsValid)
        {
            var authUser = usersManager.IsValid(user);
            if (authUser != null)
            {
                FormsAuthentication.SetAuthCookie(user.Email, false);
                response.Authenticated = true;
                if (authUser.isAdmin)
                {
                    System.Web.HttpContext.Current.Session["Admin"] = true;
                }

                var cart = (ShoppingCart)System.Web.HttpContext.Current.Session["ShoppingCart"];

                System.Web.HttpContext.Current.Session["ShoppingCart"] = new ShoppingCart(authUser.UserId, cart.Items);
                System.Web.HttpContext.Current.Session["User"] = authUser.UserId;

                return Json("/Home");
            }
        }
        string errorMessage = "Your Email and/or Password could not be found.\n Please double check credentials and try again.";
        return Json("/Home/Login?errorMessage=" + errorMessage);
    }

      

I checked FTP to make sure the web.config is up to date on the live site. However, I am still knocked out every 10 minutes. Is there anything else I can check or might be the reason?

Thank you in advance

EDIT: I am using windows azure website and am currently free trial.

+3


source to share


1 answer


It might have something to do with the IIS application pool reuse utility. It depends on the configuration of the application pool (the defaults for standard IIS are 20 minutes for idle timeout and every 1740 minutes whether the pool was idle or not), but the azure site windows are a different story:

https://www.simple-talk.com/dotnet/.net-framework/windows-azure-websites-%E2%80%93-a-new-hosting-model-for-windows-azure/



The idle wait period can fluctuate quite a bit. Currently, the waiting period starts in about 20 minutes, but then it can be as short as 5 minutes. Now you might be thinking, "Whoa! Can my site shoot even after 5 minutes of inactivity?" Yes, this is a fairly short time; however, the reason for the downtime is hesitant to deal with resource management that is accompanied by a shared system.

To avoid this behavior, you can try to publish your site periodically or use a different session mode such as SQL Server session or State Server mode. Or not use session at all and use some sort of client side storage mechanism rather than cookies or local storage (I would prefer this option).

+2


source