Tectrendz
Tectrendz

Reputation: 1464

Session Becoming Null

I am facing a problem due to which my users are logging out frequency while appearing in a Multiple choice online exam.

We have implemented exam on a single page and store the option in view state as users selects the same. On select of next question page is loaded again. Sometime "If Session("User") = """ turns out true and user logs out.

I did setup session on first time page load as

Session.Timeout = 340

Also in web config file session timeout is 2 hours.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Session("User") = "" Then
        Response.Redirect("Default.aspx")
    Else
        //Processing and updating view state.

Please help by looking into this

Upvotes: 0

Views: 4471

Answers (3)

Sunny
Sunny

Reputation: 3295

I faced this problem earlier.Please add this code in your solution.

 public int SessionLengthMinutes
    {
        get { return Session.Timeout; }
    }
    public string SessionExpireDestinationUrl
    {
        get { return "../Login.aspx"; }
    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.Controls.Add(new LiteralControl(
        String.Format("<meta http-equiv='refresh' content='{0};url={1}'>",
        SessionLengthMinutes * 60, SessionExpireDestinationUrl)));
    }

BY this you can check at what time your page redirect from main page to login page.Then we can work further and solved the problem. Hope it works for you.

Upvotes: 0

Ashwini Verma
Ashwini Verma

Reputation: 7525

Might be the reason AppPool getting recycle. Here are the some causes for that:

  1. Your sessionState timeout has expired
  2. You update your web.config or other file type that causes your AppDomain to recycle
  3. Your AppPool in IIS recycles
  4. You update your site with a lot of files, and ASP.NET proactively destroys your AppDomain to recompile and preserve memory.
  5. Or may be any file or directory deleted.

Ref:Losing Session State

Solution: use stateserver instead of InProc.

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"   cookieless="UseCookies" timeout="10" regenerateExpiredSessionId="true" />

http://msdn.microsoft.com/en-us/library/ms972429.aspx

Upvotes: 2

Jagz S
Jagz S

Reputation: 907

increase the session timeout value 525,600 minutes (1 year) in web config.

http://msdn.microsoft.com/en-us/library/ms525473(v=vs.90).aspx

http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=vs.80).aspx

Upvotes: 0

Related Questions