Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store and retrieve settings for user in asp.net mvc

Tags:

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)

like image 545
Shawn Mclean Avatar asked Apr 15 '11 22:04

Shawn Mclean


3 Answers

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?

like image 103
George Stocker Avatar answered Oct 22 '22 15:10

George Stocker


The Built in .Net Membership & Roles engine allows you to store user profile information.

Here's an intro on getting it running in MVC.

Here's a sample of someone using the API to talk to the store.

Here's some basics on the .Net Membership & Roles engine...

You'll want to focus on the Personalization part of the engine (webforms sample but you should be able to adapt).

If for some reason you need more or to do it a bit differently you can create your own provider...

like image 33
Kevin LaBranche Avatar answered Oct 22 '22 15:10

Kevin LaBranche


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
...
like image 21
Darin Dimitrov Avatar answered Oct 22 '22 16:10

Darin Dimitrov