Kiarash
Kiarash

Reputation: 1889

Managing User Specific Parameters

Can anyone give me an Idea about how to manage preferences of every user in asp.net? for example I have a couple of parameters for all my users and they are correspondingly related to the user For instance his birthday or the his salary and I need these specific parameter frequently I did save them in my database and I dont want to fetch them each time I need them Many thanks

Upvotes: 0

Views: 143

Answers (4)

StriplingWarrior
StriplingWarrior

Reputation: 156524

Normally this is stored in session state, but I'd like to say a word regarding separation of concerns. As an example, you might create a repository interface:

public interface IProfileDataRepository 
{
    ProfileData GetProfileData(Guid userId);
}

Then you use dependency injection to get an object that implements this interface where you need it, so you can retrieve it like this:

var profileData = ProfileDataRepository.GetProfileData(currentUserId);

You can begin by creating an implementation for this repository which pulls this data out of the database each time it's needed. Then you might change the implementation so that it stores the data either in the session or in an in-memory cache. The data might originate from an XML file, an SSO service, or any other source you can think of. Because you began by defining how you want to ask for the information (the interface), you can change how you actually store it at any time. If the data gets too big to fit comfortably on the session, you can move it somewhere else, whereas if you had begun by littering your code with:

var profileData = (ProfileData)Session["ProfileData"];

... it would be a huge pain to change everywhere you had done this.

Upvotes: 0

dexter
dexter

Reputation: 7203

How about extending the Profile capabilities provided by the framework?

Upvotes: 0

rerun
rerun

Reputation: 25505

My answer would be to not worry about how you store the information you need at first but worry about what information you need and how you plan to use it. Create a user information object and use it in your code. When you are ready to test plug you user object upto a data store. They type of information you want is most generally stored in a database but that is not a hard and fast rule.

Upvotes: 0

Aliostad
Aliostad

Reputation: 81660

Normally these would be fetched once and stored in the session state. A few warnings:

1) be careful on how much you store in the session. Must be up to a few KB for each user

2) With a server farm, you have to use a sticky session or store the session in SQL or state server

3) Beware of session hijack and make sure important stuff are not stored

4) Nowadays, going to database to get a few records is cheap, do not knock it automatically!

Upvotes: 3

Related Questions