I have a question about using session variables since this is the first C# 2010 web form app that I am writing.
Right now I am passing 3 session variables between 2 web pages in the web application that I setup. This is a data entry application where some information is entered on page 1 and the rest of the information is entered on page 2.
When the user has finished entering the information for the first customer. Now the user will be ready to setup information for the second user.
From what I have seen on the internet session variables last up to 20 minutes. Thus I basically do not want the information saved from customer 1 to be entered into the database file for customer 2 by using session variables.
Thus to prevent this from occuring, I am coding the following before the user clicks the button to enter data for the next customer:
Session.Remove("var1");
Session.Remove("var2");
Session.Remove("var3");
Response.Redirect("~/page1.aspx");
Can you tell me if this is the best method for clearing out session variables and/or if there is a better process you would recommend? Can you tell me and/or point me to a reference that will explain your answer to me?
Loading
Posted Jun 25, 2012, 12:09 AM
1) Avoid multiple session variables : Instead of creating multiple session variables, create one class and store the instance of the class in the session.
2) Avoid Session : Instead of passing the variables values between two pages, if possible use the wizard control and hold the object within the page itself.
3) Intermediate Save : While passing the values between two pages, if possible, save the values into DB as intermediate / incomplete record. [try this approach if it fits in your case]
Don't call Session.Remove it will remove the item from the session collection.Instead of that, Reset the session value.
Session["Var1"] = string.Emtpy;
http://stackoverflow.com/questions/261920/asp-net-removing-an-item-from-session