Problems with Session.IsNewSession - please help

Discussion in 'ASP .Net' started by rsouza, Dec 14, 2006.

  1. rsouza

    rsouza Guest

    Hi.

    Recently here in my work we added the following code in the Global.asax
    file to handled the session expired and redirect users to the home of
    the site explaining them the occurred (some thing like "Your session
    has expired, please restart your navigation.").

    public void Session_Start(Object sender, EventArgs e) {

    if(Session.IsNewSession && Request.Headers["Cookie"] != null &&
    Request.Headers["Cookie"].IndexOf("ASP.NET_SessionId") >= 0)
    {
    Response.Redirect("/index.aspx?timeout=1");
    // when the param "timeout" exists in the url the user
    receives the message "... Session expired ..."
    }
    }

    In our tests the code above works fine, but now sometimes we open the
    browser, type the url address of the site and the message "... session
    expired ..." appears. This occurs just in some machines and not all the
    times we access the site.

    Someone knows what is happening??

    Thanks

    Rodrigo
     
    rsouza, Dec 14, 2006
    #1
    1. Advertising

  2. This is completely off the top of my head, so I may be way out.

    Firstly, I'm not sure that this is best way of achieving what you seem to be
    after. What we do is to check for session timeouts in the page load event
    on each page of our applications (using Session.IsNewSession()). If it's a
    new session, we set a flag (either in a custom object, or in the Session)
    and redirect the user to the login page, which checks for the existence of
    the flag.

    Looking at your code, you need to check each element in your if statement to
    see why all of them are true.

    It appears to me that Session.IsNewSession will always be true in the
    Session_Start event handler. If the Session wasn't new, it presumably
    wouldn't be starting. So your problem, if you must use the Session_Start
    event, really is in knowing why the other two conditions are true.

    But as I said, this is right off the top of my head.


    Peter

    "rsouza" <> wrote in message
    news:...
    > Hi.
    >
    > Recently here in my work we added the following code in the Global.asax
    > file to handled the session expired and redirect users to the home of
    > the site explaining them the occurred (some thing like "Your session
    > has expired, please restart your navigation.").
    >
    > public void Session_Start(Object sender, EventArgs e) {
    >
    > if(Session.IsNewSession && Request.Headers["Cookie"] != null &&
    > Request.Headers["Cookie"].IndexOf("ASP.NET_SessionId") >= 0)
    > {
    > Response.Redirect("/index.aspx?timeout=1");
    > // when the param "timeout" exists in the url the user
    > receives the message "... Session expired ..."
    > }
    > }
    >
    > In our tests the code above works fine, but now sometimes we open the
    > browser, type the url address of the site and the message "... session
    > expired ..." appears. This occurs just in some machines and not all the
    > times we access the site.
    >
    > Someone knows what is happening??
    >
    > Thanks
    >
    > Rodrigo
    >
     
    Peter Bradley, Dec 14, 2006
    #2
    1. Advertising

  3. rsouza

    Mark Rae Guest

    "rsouza" <> wrote in message
    news:...

    > Someone knows what is happening??


    Get rid of the check for the cookie - it's not necessary.
     
    Mark Rae, Dec 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anders Borum
    Replies:
    0
    Views:
    3,444
    Anders Borum
    Jun 9, 2004
  2. mtcc
    Replies:
    2
    Views:
    993
    Derek Harmon
    Oct 2, 2005
  3. Mirek Endys

    OnSessionStart or IsNewSession

    Mirek Endys, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    4,012
    Steven Cheng[MSFT]
    Mar 2, 2006
  4. zee

    Problem with isNewSession

    zee, Dec 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    715
    bruce barker
    Dec 22, 2006
  5. daokfella

    Session.IsNewSession Always True

    daokfella, Aug 4, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    2,092
    Hans Kesting
    Aug 5, 2008
Loading...

Share This Page