Session variable expiring prematurely.. HELP!

Results 1 to 2 of 2

Thread: Session variable expiring prematurely.. HELP!

  1. #1
    Join Date
    Dec 1969

    Default Session variable expiring prematurely.. HELP!

    Hello,<BR>I am developing an simple ASP app, in which a user logs in, performs their tasks, and logs out.<BR><BR>I am finding a problem with Session variables seeming to expire prematurely. When a user login in, I grab the users ID (from a table) and store it and other variables in the Session. Im currently setting the session timeout to be 120 minutes..<BR><BR>strUserID = trim(rstLogin("UserID"))<BR>Session("UserID") = trim(rstLogin("UserID"))<BR>Session("FullName") = trim(rstLogin("FullName"))<BR>Session("UserName") = trim(rstLogin("UserName"))<BR>Session("UserTypeCd" ) = trim(rstLogin("UserTypeCd"))<BR>Session("UserStatu sCd") = trim(rstLogin("UserStatusCd"))<BR>Session("Success ") = "Yes"<BR>Session("LoginTimestamp") = Timestamp<BR>Session.Timeout = 120<BR>Server.ScriptTimeout = 300<BR><BR>However, in a somewhat random fashion, users are experiencing errors if they remain idle for a little while (like 10-15 minutes, nothing close to 120 minutes)... <BR><BR>And they get errors because I use the Session UserID to identify the user on different pages, perform SQL updates etc... For example.. if the user logged in, waited about 15 min, and then tried to log out, they would get an error on logout...<BR><BR>strUserID = Session("UserID")<BR>strLoginTimestamp = Session("LoginTimestamp")<BR>strLogoutTimestamp = Now()<BR><BR>strSQL = "UPDATE tblLoginRecord SET LogoutTimestamp = &#039;" & strLogoutTimestamp & _<BR>"&#039; WHERE UserID = &#039;" & strUserID & "&#039; AND LoginTimestamp = &#039;" & strLoginTimestamp & "&#039;"<BR><BR>dbConn.Execute strSQL<BR><BR>Session("Success") = "No"<BR>Session("FullName") = ""<BR>Session("UserID") = ""<BR>Session("UserName") = ""<BR>Session("UserTypeCd") = ""<BR>Session("LoginTimestamp") = ""<BR>Session("UserStatusCd") = ""<BR>Session.Abandon<BR><BR>The error occurs in the SQL Execute because strUserID is blank.<BR><BR>Any suggestions?<BR>Thanks<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Session variable expiring prematurely.. HELP!

    I had same problem a lont time ago where it was finicky sometimes...<BR><BR>When I put my <BR>Session.TimeOut = 20<BR>As being the 1st session value to be set... (Instead of close to the end as you have...)<BR><BR>Then I didnt have any more probs...<BR>(I dont know why)<BR><BR>As far as your errors go...<BR>You should be checking for them "Before" you execute any code...<BR><BR>Meaning at the top of page.<BR>IF Session("UserID") = "" THEN<BR>Response.Redirect "ToLoginPage"<BR>End IF<BR><BR><BR>This way if session expires, or somone had bookmarked the page, if no session variable exists, then go back to login and dont execute code...<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts