views:

47

answers:

1

Hi,

In my application I have the requirement to store, for the period the user stay logged in, some variables that's used to provide a customized experienced on how the user views it's data (pre-defined filters, language, etc.). My needed data is not more than 1Kb.

I have read many blog posts that definitely encourage to not store this data in the Session object. In many of these blog posts the authors suggests to use TempData instead.

As I understand TempData is a good choice for short-lived temporary data and not suitable for caching data during all the period the user stay logged.

Does am I wrong? What is a good alternative suitable to my scenario?

thanks for helping :)

+2  A: 

Two options:

  1. Cookies
  2. Database

If this information needs to be stored only for the time the user is logged in and you don't want to persist it when he comes back cookies would work just fine. If on the other hand you want to persist the user's customized settings then you need to store them in the database or use persistent cookies.

Session is also an option but be careful if your site runs in a web farm - in this case you will need an out-of-proc session persistence.

As I understand TempData is a good choice for short-lived temporary data and not suitable for caching data during all the period the user stay logged.

You are absolutely right. TempData should be used only in the following scenario: a user calls a controller action, this controller action stores something into the TempData and immediately redirects to another controller action (it never renders a view) which fetches the stored data and renders a view (Redirect After POST scenarios).

Darin Dimitrov