Can I strore arraylists in cookies or someotherway?
I'm doing a room reservation website and I have implemented 3 arraylists that contain the clients room types, room number and total price. I pass these arraylists to 3 other static arraylists in an AppCode class. I made those static since that's the only way to keep the values in there. My problem is that this works for a single browser, but whenI try with multiple browsers, and insert data into any of the arraylists, bcos they are static they affect other client browser requests.
I need to know how I can prevent this or another method of passing arraylists to other web forms taking note of sessions.
Thanks in advance.
Kobi
Status:
Open Jul 12, 2006 - 11:24 AM
web development
2answers
Answers
Jul 12, 2006 - 07:23 PM
First of all, what programming language do you use? .Net? Java? What environment? ASP?
I can give you an answer for .Net. You have three areas in .Net where you can save information: Viewstate, Session State and Application state. Depending on where and how you want to use the information you select the correct area.
Viewstate:
information is available for the same webpage. Example, you load data into a drop down field and want to load it only once for this page. You enable viewstate for the drop down component and it keeps the data between posts
Session state:
you want to have data available for the same session but across different web pages/forms. You can save almost anything which is serializable to Session state. And session state can be held in memory of the web server, on another state server or even in a database. Key is the session ID
You create a new entry in session state in C# with:
String[] MyArray;
//Fill array or do something
Session["MyArray"] = MyArray;
You retrieve Session state data with
AnotherArray = Session["MyArray"];
Application state:
If you want to make data available across sessions. I.e. global data for every user!
Note, Application State has to be initialized before you can use it. Best place to do thi sin an ASP.Net app is in the ApplicationStart Event.
You create Application state with
Application["AppCount"] = 0;
You can then use Application["AppCount'} on every page in this application. Across sessions and users!
Let me know if you need more information
Cheers
Peter
Jul 14, 2006 - 11:23 AM
Thanks Pete. I happened to have bumped into the solution yesterday, that i could use ASP.NET's Session[] class to store my arraylists and retrieve them by casting the Session variable as an arraylist. It works now. However have you tried using the HttpCookies class? It seems that b'cos of the size limitation imposed when using client cookies, Errors are flagged when you try to store a cookie with the HttpCookie class. I could be wrong, but that's my observation. Anyway lessons learned and Thanks a lot for the help.
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment