mare
mare

Reputation: 13083

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 allowed 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?

Upvotes: 1

Views: 1743

Answers (3)

Russ Cam
Russ Cam

Reputation: 125528

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.

Upvotes: 3

John Farrell
John Farrell

Reputation: 24754

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?

Upvotes: 0

Jesus Rodriguez
Jesus Rodriguez

Reputation: 12018

Maybe this sounds so stupid but.. what about storing the info into an object and putting that object in the session?

Upvotes: 1

Related Questions