0

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

Chris Taylor
  • 52,623
  • 10
  • 78
  • 89
Tectrendz
  • 1,354
  • 2
  • 17
  • 36
  • 1
    You need to set the Forms Authentication timeout to 2 hours too. – TheGeekYouNeed Jun 04 '12 at 03:09
  • A few questions: First, are you using inproc or out of proc session state? Have you checked the Windows eventlog for messages that might indicate that the application is being recycled? – Chris Taylor Jun 04 '12 at 03:10
  • @TheGeekYouNeed- thanks, seems i didn't set Forum Authentication timeout. I did a quick serarch and seems following call will set the same. System.TimeSpan.FromMinutes(120) . Please reply on this. – Tectrendz Jun 04 '12 at 03:18
  • @ChrisTaylor, Thanks for the quick reply. Going to try mode="InProc" and soon update. Also restart on config change is set as False.. not sure if i have access to windows logs.. i will check if on my hosting i have access.. Will soon come back – Tectrendz Jun 04 '12 at 03:20
  • @ChrisTaylor i tried "InProc" but still see the issue – Tectrendz Jun 04 '12 at 03:28
  • @TheGeekYouNeed I added following on page load still seeing the session variable getting null (Session("User") = "") Session.Timeout = 120 System.TimeSpan.FromMinutes(120) – Tectrendz Jun 04 '12 at 04:38
  • @tectrendz, I did not realize this was with a hosting company. I had a similar problem when I changed hosts, I created a test application that showed the session id and then every few minutes I would get a new session. Fortunately the online support was excellent, I contacted them demonstrated the issue by directing them to my test page. After they reviewed the setup, they changed something and the issue was resolved, they claimed my app was being re-cycled due to memory or CPU over-utilization, but just my simple page could demo the problem and they resolved it. – Chris Taylor Jun 04 '12 at 15:57
  • Session timeout and FormsAuthentication timeouts are two different things. – TheGeekYouNeed Jun 04 '12 at 18:25

3 Answers3

2

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

Community
  • 1
  • 1
Ashwini Verma
  • 7,477
  • 6
  • 36
  • 56
0

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

Jagz W
  • 855
  • 3
  • 12
  • 28
  • Thanks but I see session variable becoming null with in 5 minutes and session variable is set as 120 minutes – Tectrendz Jun 04 '12 at 03:32
0

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.

Sunny
  • 3,185
  • 8
  • 34
  • 66