Where to store a user specific setting after logon?
In my ASP.NET MVC application I allow users to log in. Each user is associated with a company. Company ID and company data is not part of the Users table in the database. User and Company are connected through a related table (one to many relationship). Company ID is not part of the Users table as a foreign key because the design of the Users table did not predict that and we are not a开发者_Go百科llowed to change it.
When user logs on we want to take the company ID for this user and store it somewhere. We would use this ID later for querying and other kinds of filtering by company because the content is stored per company.
Where should I store the company ID setting to make it persistant over many web request?
I see three viable options
Session
Cookie
This may or may not be in the authentication cookie, your choice.Keep it in the database
Query as and when needed. If it's needed less than x% of the time, just fetch it as and when needed from the datasource.
Maybe this sounds so stupid but.. what about storing the info into an object and putting that object in the session?
Most people use Session or Cookies for this type of functionality:
Can't answer any better than the answers in this question:
Cache VS Session VS cookies?
精彩评论