Shawn Mclean
Shawn Mclean

Reputation: 57469

Store and retrieve settings for user in asp.net mvc

Is there an easy way to store user settings in an asp.net mvc app? For example, settings such as how often they want notifications, where to send notifications and anything else you can think of that the user would personalize for themselves.

Is there some built in thing in .net that can do this? I'd like to store the settings in the database with a foriegn key that links to that user.

If there is no built in .net features for this, how would I design my database table for settings? (just an example)

Upvotes: 7

Views: 7309

Answers (3)

George Stocker
George Stocker

Reputation: 57907

Do you want them to be persistent? If there aren't many of them, store them in a cookie.

If you can't store them in a cookie, then store them in a database table:

UserPreferences
---------------
Id
UserId
PreferenceName
Value

If you're worried about normalization and all that, then you could always add another table:

Preferences
-------------
Id
Name
Type

And your UserPreferences table would become:

UserPreferences
---------------
Id
UserId
PreferenceId
Value

I could go forever on possible tables, or persistence mechanisms. The question is, what sort of preferences are these? Session? Lifetime?

Upvotes: 9

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

Well you could have a table in the database that will contain the user preferences:

Preferences
-----------
Id       <- PK
UserId   <- FK pointing to the User table
Setting1
Setting2
...

Upvotes: 2

Related Questions