Sam
Sam

Reputation: 432

SessionState Expires before timeout

I have 2 session in my web application
here how i'm declaring my session:
Global.asax

protected void Session_Start(object sender, EventArgs e)
    {
        Session["login"] = "";
        Session["loginName"] = "Login";

    }

Web.config

<sessionState mode="InProc" cookieless="true" timeout="3600" /> <!--set the session timeout in minutes -->

sessions class:

    public class clsSession
{
    //declare sessions
    private static object cardCode;
    private static object cardName;       

    //get/set Login id session
    public static string LoginIdSession
    {
        get
        {
            cardCode = HttpContext.Current.Session["login"];
            return cardCode == null ? "" : (string)cardCode;
        }
        set
        {
            HttpContext.Current.Session["login"] = value; 
        }
    }

    public static string LoginNameSession
    {
        get
        {
            cardName = HttpContext.Current.Session["loginName"];
            return cardName == null ? "Login" : (string)cardName; 
        }
        set
        {
            HttpContext.Current.Session["loginName"] = value;                 
        }
    }
}

the problem is the 2 sessions expire before timeout!

Thank you

Upvotes: 0

Views: 5781

Answers (1)

Usman Khalid
Usman Khalid

Reputation: 3110

Well there could be lot of reasons for that. Some of them are:

  • Machine.Config, Web.Config or Global.asax are modified
  • The bin directory or its contents is modified
  • The physical path of the virtual directory is modified
  • There are few settings in IIS that can cause application pool or worker process to be recycled.
  • If you have web farms setup, you need to use Out-Proc session state(StateServer or SQL Server)

Also check, IIS:

Right click on application pool -> properties

Recycling Tab -> "Recycle worker process (in minutes)" if this option is checked, make sure time set here should be the same as session timeout set in web.config.

Performance Tab -> "Shutdown worker processes after being ideal for" Make sure time set here should be the same as session timeout set in web.config

Upvotes: 1

Related Questions