Handling User Specific Information in a Web Application

I have some information about a user I need to store and access in an ASP.NET MVC 5 application. Here are some of the things that I will need to store/access:

  • Theme choice
  • If they want to show panel bar navigation
  • If they want to show menu bar navigation
  • If they want to hide unauthorized links
  • etc.

I am trying to figure out what is an efficient way of doing this. I could store the user specific information in a database. Then use a view model and pass the user specific information along with the other data the page needs. Doing so would cause me to query the database on each new page load.

Another option is to use session state. But in reading up on it I see a lot of people saying it is problematic and should be avoided whenever possible.

Is there another way of handling user specific information that I am missing?

You may consider a combining your options: Keep the user info in the database for long-term persistence but only query at login (or whatever is appropriate). Then cache this in Session, cookies, or some other client-side local storage to avoid additional queries.

In many web applications, it would be considered very normal to store this information in the database and pass it along as you suggest. That’s the approach I would take.

If for some reason you don’t already have a database, you could consider stuffing this sort of preference into cookies. That’s assuming the amount of data is small, losing it doesn’t matter much, and there’s nothing security or privilege-related in there. Only consider cookies if losing the data (user wiped the cookies) doesn’t cause any lasting harm.


Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *