Anshu sharma
Anshu sharma

Reputation: 11

Session timeouts unexpectedly

I am facing a very strange problem. Actually I developed a web application in ASP.NET using C#. My application has two parts: one for administrator and second for user. When I run my application on local server it works fine but when I host it on remote server I am facing n strange issue. The problem is that when I navigate through my application or click on any button or link button, sometimes it redirect to login page. I am not understanding what is the problem. I check session on each page like this:

    if (Session["admin"] != null)
    {
        // do some thing.
    }
    else
    {
        Response.Redirect("AdminLogin.aspx");
    }

And I set session time out in web.config file <sessionState mode="InProc" timeout="10000"></sessionState> but still I am facing this problem. So can any one help me please? Thanks.

Upvotes: 0

Views: 697

Answers (1)

RickNZ
RickNZ

Reputation: 18652

If you're using InProc sessions, it's possible that your application pool is timing out due to inactivity (IIRC, the default is 20 minutes). When that happens, the IIS process exits, and your session state will be lost, since it lives in memory.

The solution is to either switch to SQL Server based session state, or perhaps State Server, or to disable AppPool idle timeouts (and recycling, which can cause the same problem).

Upvotes: 2

Related Questions