Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. persist session variables

persist session variables

Scheduled Pinned Locked Moved ASP.NET
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PandemoniumPasha
    wrote on last edited by
    #1

    hi, can anyone explain if it is normal for the session variable to disappear after writing to a file. if yes what can i do (work around?) to make them persist even after writing to a file. thanks.

    S S 2 Replies Last reply
    0
    • P PandemoniumPasha

      hi, can anyone explain if it is normal for the session variable to disappear after writing to a file. if yes what can i do (work around?) to make them persist even after writing to a file. thanks.

      S Offline
      S Offline
      Sam Heller
      wrote on last edited by
      #2

      No there is no reason why this should happen.

      1 Reply Last reply
      0
      • P PandemoniumPasha

        hi, can anyone explain if it is normal for the session variable to disappear after writing to a file. if yes what can i do (work around?) to make them persist even after writing to a file. thanks.

        S Offline
        S Offline
        Sandeep Akhare
        wrote on last edited by
        #3

        This should not happen Might be session timeout or you are closing the session (unknownly) Can you post the code What you have done while writing to file ?

        Thanks and Regards Sandeep

        P 1 Reply Last reply
        0
        • S Sandeep Akhare

          This should not happen Might be session timeout or you are closing the session (unknownly) Can you post the code What you have done while writing to file ?

          Thanks and Regards Sandeep

          P Offline
          P Offline
          PandemoniumPasha
          wrote on last edited by
          #4

          here is the code: when the user clicks the login button the following code gets executed: Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click ' Attempt to Validate User Credentials using UsersDB from XML file Dim accountSystem As New ProcessNowUser if accountSystem.AuthenticateUser(txtUserID.Text, txtPassword.Text) Then Session("UserID") = accountSystem.UserID Session("DisplayName") = accountSystem.UserName FormsAuthentication.RedirectFromLoginPage(accountSystem.UserName, False) Else Message.InnerText = "Sorry ! Login Failed. Please try again." End If End Sub when the user clicks the change password button the function below is called and the new password is saved in the XML file. But when the page reloads the all session variables lose their value. Private Sub btnChangePassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePassword.Click If isPageValid() Then Dim changePwd As New ProcessNowUser Dim sResults As String = changePwd.ChangePassword(Session("DisplayName").ToString.Trim, txtCurrentPassword.Text.Trim, txtNewPassword.Text.Trim) If sResults.Equals("No Password") Then ShowMessage("Password doesnot match!", Me) Else ShowMessage("Password changed successfully!", Me) End If End If End Sub Public Function ChangePassword(ByVal userName As String, ByVal OldPassword As String, ByVal NewPassword As String) As String Dim returnValue As String = "" Dim dvUsers As DataView = _dsDataStore.Tables("Users").DefaultView dvUsers.RowFilter = "username='" & userName & "'" If dvUsers.Count > 0 Then Dim sPublicKey As String = dvUsers(0)("key") Dim sEncryptedPassword As String = dvUsers(0)("password") Dim sDecryptedPassword As String = Utility.DecryptTripleDES(sEncryptedPassword, sPublicKey) If sDecryptedPassword = OldPassword Then dvUsers(0)("password") = Utility.EncryptTripleDES(NewPassword, sPublicKey) dvUsers(0)("key") = sPublicKey updatexmlOnly(_dsDataStore) returnValue = "OK" Else returnValue = "No Password" End If Else returnValue = "No User" End If Return returnValue End Function Private Sub updatexmlOnly(ByVal ds As DataSet) If IO.File.Exists(_sTargetDirectory & XML_DATA_DIRECTORY & "adminuser.xml") Then IO.File.Delete(_sTargetDirectory & XML_DATA_DIRECTORY & "adminuser.xml") End If ds.WriteXml(_sTargetDirectory

          M 1 Reply Last reply
          0
          • P PandemoniumPasha

            here is the code: when the user clicks the login button the following code gets executed: Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click ' Attempt to Validate User Credentials using UsersDB from XML file Dim accountSystem As New ProcessNowUser if accountSystem.AuthenticateUser(txtUserID.Text, txtPassword.Text) Then Session("UserID") = accountSystem.UserID Session("DisplayName") = accountSystem.UserName FormsAuthentication.RedirectFromLoginPage(accountSystem.UserName, False) Else Message.InnerText = "Sorry ! Login Failed. Please try again." End If End Sub when the user clicks the change password button the function below is called and the new password is saved in the XML file. But when the page reloads the all session variables lose their value. Private Sub btnChangePassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangePassword.Click If isPageValid() Then Dim changePwd As New ProcessNowUser Dim sResults As String = changePwd.ChangePassword(Session("DisplayName").ToString.Trim, txtCurrentPassword.Text.Trim, txtNewPassword.Text.Trim) If sResults.Equals("No Password") Then ShowMessage("Password doesnot match!", Me) Else ShowMessage("Password changed successfully!", Me) End If End If End Sub Public Function ChangePassword(ByVal userName As String, ByVal OldPassword As String, ByVal NewPassword As String) As String Dim returnValue As String = "" Dim dvUsers As DataView = _dsDataStore.Tables("Users").DefaultView dvUsers.RowFilter = "username='" & userName & "'" If dvUsers.Count > 0 Then Dim sPublicKey As String = dvUsers(0)("key") Dim sEncryptedPassword As String = dvUsers(0)("password") Dim sDecryptedPassword As String = Utility.DecryptTripleDES(sEncryptedPassword, sPublicKey) If sDecryptedPassword = OldPassword Then dvUsers(0)("password") = Utility.EncryptTripleDES(NewPassword, sPublicKey) dvUsers(0)("key") = sPublicKey updatexmlOnly(_dsDataStore) returnValue = "OK" Else returnValue = "No Password" End If Else returnValue = "No User" End If Return returnValue End Function Private Sub updatexmlOnly(ByVal ds As DataSet) If IO.File.Exists(_sTargetDirectory & XML_DATA_DIRECTORY & "adminuser.xml") Then IO.File.Delete(_sTargetDirectory & XML_DATA_DIRECTORY & "adminuser.xml") End If ds.WriteXml(_sTargetDirectory

            M Offline
            M Offline
            Marcus J Smith
            wrote on last edited by
            #5

            Is this process taking longer than the session timeout (default 20 minutes)?


            Cleako

            P 1 Reply Last reply
            0
            • M Marcus J Smith

              Is this process taking longer than the session timeout (default 20 minutes)?


              Cleako

              P Offline
              P Offline
              PandemoniumPasha
              wrote on last edited by
              #6

              no, completes as soon as the button is clicked and the page reloads. but unfortunately, the session variables = Nothing:confused:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups