Darien Fawkes
Darien Fawkes

Reputation: 3103

How save a variable from session and get when session is null?

I Write into a session user login. I need to get user login on server side page when a session is dropped. I try:

 private string currentUserLogin;
 protected void Page_Load(object sender, EventArgs e)
 {   
      if (!IsPostBack)
      {
          if (HttpContext.Current.Session["curUserRole"] == null)
          {
               // try to get a "currentUserLogin" varialbe, but it null!
          }
          else
          {
               currentUserLogin = HttpContext.Current.Session["curUserLogin"].ToString();                   
          }
      }
 }

Upvotes: 0

Views: 181

Answers (2)

paparazzo
paparazzo

Reputation: 45096

In the Global.asax there is a SessionEnd event. I use it to write to write to to a log file the userID and logoff date/time.

Upvotes: 0

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Store the information from the session into cookie (with desired expiration time) & retrieve the value from cookie when session expires.

Upvotes: 1

Related Questions