Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What's the best way to store information for client/session in ASP.NET except Session Variables?
Posted

There are many ways to store data besides session variables.
Pick one that is most useful to you - ASP.NET State Management Recommendations[^].

Points to ponder before picking the best mechanism -
How much information do you need to store?
Does the client accept persistent or in-memory cookies?
Do you want to store the information on the client or on the server?
Is the information sensitive?
What performance and bandwidth criteria do you have for your application?
What are the capabilities of the browsers and devices that you are targeting?
Do you need to store information per user?
How long do you need to store the information?
Do you have a Web farm (multiple servers), a Web garden (multiple processes on one machine), or a single process that serves the application?
 
Share this answer
 
v2
Comments
iamalik 11-Apr-15 13:28pm    
Abhinav S, I just asked one question and looking for one answer, but found number of questions Smile | :)

I want to store different small strings like a user's name. Number of these string variables can be as much as twenty. And I want to store it as long as User's session exits. It will be a single server application.
Maciej Los 12-Apr-15 4:31am    
+5
Abhinav S 12-Apr-15 4:38am    
Thank you.
When it comes server-side session data it could be that storing the data in the application is the better option so long as the size does not become too big or you need to use a web-farm, Garden, Sticky session server

When saved as server-side session data the data needs to be serialized and de-serialized which is slow but thats not the case with data stored in the application and anything that's slow has an effect on scaleability so it's not always a clean cut case.

Microsoft loves session data because they like to push for selling another windows licence to run a session server or for dumping sessions to a SQL-Server because that again makes a profit but if you took a deep hard look at making something scale then ASP.Net with all its view state processing and huge amounts of overheads when converting an object models to what is after all just a HTML string then you would not opt for ASP.NET in the first place IMHO.

Caching data as XML tables in the file system for data that comes from a DB that is more is less static is well worth looking at because some data feed pages need to make ten or more hits on the DB to render and each time the DB is hit the connction needs to be negociated, permission checked, record locked (well unless NO_LOCK is used) and then all the logging, packaging the results plus more ! Well it all takes time and soon slows a page down and that stops sites from scaling too.

Less code is often better code but this lesson seems to be lost on a lot of people.
 
Share this answer
 
In addition to server-side storage, there is a very important way for storing data on the client side, Web storage and DOM storage: http://en.wikipedia.org/wiki/Web_storage..

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900