locked
Session handling in page_load or Page_init? -Urgent RRS feed

  • Question

  • User871748133 posted

    Hi,

    I have problem in session handling.But everytime the session expires.i face these problem:

    1) Everytime session does not expire at 30 minus.It may vary ..I dont why this happens.
    2) When the session expires, It says its not able to find the login page.Even though it exsist in the directory outside the page folder.
    3)Sometimes the page_Init is not executed.Is it because, i have to check for session in Page_load?

    I'm not using authentication mode="forms" in web.config as i have my own login checking.

    Please help

    Here is my web config file:

    <sessionState mode="InProc" cookieless="false" timeout="30"/>

    Here is my way of redirectig the page to login.
    Sub Page_Init(ByVal Sender As Object, ByVal E As EventArgs)

    CheckSession()

    End Sub

    Private Sub CheckSession()

    Dim objChkSessionId As String

    objChkSessionId = Session("SesUserId")

    If objChkSessionId = "" Then

    Response.Redirect("~/Login.aspx?Yoursession=expired")

    Else

    Dim SalesuserId As Guid = New Guid(Session("SesUserId").ToString())

    End If

    End Sub

    Wednesday, January 21, 2009 12:07 PM

Answers

  • User533502567 posted

    1) Everytime session does not expire at 30 minus.It may vary ..I dont why this happens.

    This can happen for many reasons. Did you increase session time in IIS also?

    3)Sometimes the page_Init is not executed.Is it because, i have to check for session in Page_load?

    Page_Load is prefered for this. Or else add this code to page_Load..  

    HttpContext.Current.Response.AppendHeader("Refresh", Convert.ToString(((HttpContext.Current.Session.Timeout * 60) - 10)) + "; Url=Login.aspx?Yoursession=expired");
    The above code will refresh the page in the client side and will redirect to login page on session expiration.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 21, 2009 1:07 PM