Checking session value exists, or redirect to root

Last post 07-04-2009 4:34 AM by adeelehsan. 1 replies.

Sort Posts:

  • Checking session value exists, or redirect to root

    07-03-2009, 10:56 AM
    • Participant
      1,223 point Participant
    • jmurdock
    • Member since 10-23-2002, 7:13 PM
    • Ontario Canada
    • Posts 341

     I have an application which relies on session variables to work properly. I have code which checks to see if the session values exist, if they do not redirects them to the login page so they can re-log in. (They have most likely timed out).

    I use usercontrols on most but not all of the pages.

    The code does not always work. I COULD call it from every event that could cause a postback but then I'd need to remember that. I have tried putting it in the page_load but it does not always work there.

    I have tried putting it in the page_load of the controls as well, but it does not always work there either.

    When you have a page which has multiple usercontrols, and a postback occurs what is the order of operation? Does the 'page' execute first and then the controls (So I should find the right place at the page level) or does the control execute first?

    Where should I call this routine from, or do I have to remember to call it from all possible post back operations (ie: button presses, controls that cause post back etc.)

     

    Ask One/Answer One.
  • Re: Checking session value exists, or redirect to root

    07-04-2009, 4:34 AM
    Answer
    • Member
      549 point Member
    • adeelehsan
    • Member since 07-18-2005, 6:56 AM
    • UAE
    • Posts 94

    Hello

    You do not need to put session check in load event of every control. You can just put it in the load event of the page or put it in the load event of one control. The load event of the page is called first.

    If for some reason your code is not working always, just make sure you are using the following for the session checking:

    if (HttpContext.Current.Session("SomeKey")="SomeValue") then

    .....................

    Because sometimes it solves the problem.

    Please Mark AS Answer if it helped.
    Regards
    ADEEL EHSAN
    Filed under:
Page 1 of 1 (2 items)
Microsoft Communities