persist session variables
-
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.
-
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.
No there is no reason why this should happen.
-
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.
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
-
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
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
-
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
Is this process taking longer than the session timeout (default 20 minutes)?
Cleako
-
Is this process taking longer than the session timeout (default 20 minutes)?
Cleako
no, completes as soon as the button is clicked and the page reloads. but unfortunately, the session variables = Nothing:confused: