在ASP.NET MVC中存储和检索用户的设置 [英] Store and retrieve settings for user in asp.net mvc
问题描述
是否有一种简单的方法将用户设置存储在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.
.net中是否有内置的东西可以做到这一点?我想使用链接到该用户的外键将设置存储在数据库中.
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.
如果没有内置的.net功能,我将如何设计数据库表进行设置? (只是一个例子)
If there is no built in .net features for this, how would I design my database table for settings? (just an example)
推荐答案
您是否希望它们具有持久性?如果没有很多,请将它们存储在cookie中.
Do you want them to be persistent? If there aren't many of them, store them in a cookie.
如果您无法将它们存储在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
您的UserPreferences表将变为:
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?
这篇关于在ASP.NET MVC中存储和检索用户的设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!