Handling MVC Session for every page
In fairly new to MVC and I would like to use a session. I have a base controller and all my other controller inherit from my base. I need the session checked every time a page is hit.
What is the best开发者_如何学编程 way to go about this?
Updated
My session will need to store an id to be able to build the pages correctly. If the session doesn't have the ID I need to look up the information in DB. I don't want to use cache because IDs could be different for different users.
I recommend going the cache route.
Create a class called 'CacheHelper' and within it, a method called 'GetId()' In the GetId() method, setup a Dictionary object to store your values and use the username as the key. Each time you call GetId, check to see if the Key exists in your dictionary
myDictionary.ContainsKey(username);
If not, look it up in the database, add it to the dictionary, then resave it to cache.
精彩评论