storing user data
In my application user can personalize their settings like background-image,use https etc. How should i add these setting to users page.I mean should i store these setting like bacjgr开发者_运维百科ound-image in session.What is the better way of dong it.I am using ASP.Net MVC. Please help.
Maybe my answer on the question how to change the themes in asp.net mvc 2 can help you.
ASP.Net Profiles is used in such cases
There are really two options here
- You can use the Profile functionality build into ASP.NET
- Build your own class and then store the user settings in a table in the database
With option one there are plenty of tutorials and a good video on the ASP.NET website: http://www.asp.net/general/videos/how-do-i-customize-my-site-with-profiles-and-themes
With option two you would want to produce a user settings class which might look like this:
public class UserSettings{
public int UserId {get;set;}
public string BackgroundImage {get;set;}
public bool UserHttps {get;set;}
}
There would be a database table or some sort of persistent store the class was mapped onto. If you want to avoid a trip to the database every request you can pull an instance of the class from the database the first time the user logs in and then cache them somewhere. The cache could be the session, a cookie, the application cache etc.
精彩评论