locked
Session variable, get last update time? RRS feed

  • Question

  • User-802546231 posted

    I have an application where I want some session variables to persist longer than others, does anyone know if this is possible?

     

    Alternatively I would like to be able to get the time when a session variable was last updated so I can calculate if it needs updated again, I can't spot any obvious way to do this, anyone got any ideas?

    Thursday, August 2, 2012 11:00 AM

Answers

  • User1779161005 posted

    I have an application where I want some session variables to persist longer than others, does anyone know if this is possible?

    Session is all-or-nothing, meaning all the values stored in session are set until you explicitly remove one (or all) or the entire session expires.

    Alternatively I would like to be able to get the time when a session variable was last updated so I can calculate if it needs updated again, I can't spot any obvious way to do this, anyone got any ideas?

    There's nothing like this built in, so you'd need to track this yourself. One idea would be a DateTime in Session for each key you want to track, so:

    Session["Name"] = "Brock";
    Session["Name.LastUpdate"] = DateTime.Now;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 2, 2012 11:03 AM

All replies

  • User1779161005 posted

    I have an application where I want some session variables to persist longer than others, does anyone know if this is possible?

    Session is all-or-nothing, meaning all the values stored in session are set until you explicitly remove one (or all) or the entire session expires.

    Alternatively I would like to be able to get the time when a session variable was last updated so I can calculate if it needs updated again, I can't spot any obvious way to do this, anyone got any ideas?

    There's nothing like this built in, so you'd need to track this yourself. One idea would be a DateTime in Session for each key you want to track, so:

    Session["Name"] = "Brock";
    Session["Name.LastUpdate"] = DateTime.Now;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 2, 2012 11:03 AM
  • User-802546231 posted

    There's nothing like this built in, so you'd need to track this yourself. One idea would be a DateTime in Session for each key you want to track, so:

    Session["Name"] = "Brock";
    Session["Name.LastUpdate"] = DateTime.Now;

     

    good thinking! that should do the job nicely for what I need, thank you!

    Thursday, August 2, 2012 11:50 AM