0

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();                   
          }
      }
 }
7
  • 1
    what do you mean when session is dropped? are you trying to access session after session timeout? Commented May 24, 2012 at 14:33
  • Where is the HttpContext.Current.Session["curUserRole"] = someValue; in your code? Do you set the session value anywhere? Commented May 24, 2012 at 14:33
  • I to use variable that was in session after session timeout Commented May 24, 2012 at 14:34
  • Data write into session when user login on site Commented May 24, 2012 at 14:34
  • Is there a reason you aren't just making the session timeout longer so that you don't need to access it after it is expired? Commented May 24, 2012 at 14:40

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

User Roles and User Logins are not for cookies, This stuff should be Database driven. However you are right in saying it can't be session stored.
0

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.

1 Comment

It should be pointed out that the SessionEnd event only works when your session store is in-memory, not when you are using a State Server or SQL Server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.