Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing user variables in database vs session in asp.net

I'm working with an asp.net application that stores most data in a database and not session. I'm wondering of the pros and cons of each and which is the better way to go. For example, you have a pretty busy site and instead of storing user specific variables in session, there is a DB table called user data and it can store all user specific data that can be accessed from any page by querying the database. Which is the better way to go, session or database?

like image 461
user204588 Avatar asked Jul 28 '10 15:07

user204588


People also ask

What should not be stored in session?

Things like Database Data such as User Rows should not be stored in the session and you should create a separate cache mechanism to do this for you.

What is difference between session and application variable?

application variable creates only one memory for one variable and for all user . while session creates one memory for one variable for one user :) Application variable will be maintained like global variable. Ex if I create a application session in my project and assign this value 1.

Are session variables shared between users?

No, it is not shared.

Do session variables use cookies?

no, stored on server somewhere in tmp folder. sessions are serverside, cookies are client side. Cookies are the default method of tying a user's session id to the session data on the server.


1 Answers

Session (but it depends a lot of the session configuration) :

  • No database access, or less.
  • Temporary storage : you may lose the information, at least when the session ends.
  • Maybe some security issue, depending on where you store the session information
  • Not shared : you may have issues if you're using a server farm, one server may not have access to the other server session.
  • May not work if the client disabled the cookies.

Database :

  • Database traffic for each postback if you need the information on each page.
  • Permanent storage.
  • No information stored with the client (cookies...).
  • Shared : data accessible from any server on a web farm.

Please note that you can store Session information in database. That's why I use the word "may" in the Session part. See here some session configuration and possibilities

like image 52
Julien N Avatar answered Oct 12 '22 22:10

Julien N