views:

137

answers:

1

Hi,

I am developing an e-commerce app using asp.net mvc.

After user successfully logged into system the application is pulling additional data from database (favorites, order history, unfinished cart etc.)

What is the best way to pull that data in case if user used Remember me option?

I am thinking to check if user is authenticated and additional data is not already loaded on master page but is seems not the best solution.

+1  A: 

I have a user class that collects all of those bits together.

On session start, I check for authentication, create it, populate it, and store it in the session variable. Then you can access it from wherever you please (I've also created a Globals static class that gets/casts objects from the session and application variables.) Alternatively, you could do it on each page load.

The above takes care of returning users. But you also have to remember to create it on login, and destroy it on logout (from the Accounts controller).

Also, I would suggest you think about what exactly needs to be stored in this way. The session variable is great to cache this data, but I don't know if order history needs to be cached. That's generally only accessed occasionally. In fact, even if you choose not to put the class in the session, and to create it on each page load, it seems like overkill to get order history. (Either way you're wasting resources -- storing it in the cache or collecting it frequently.)

James

James S
I do have lightweight User class that I am storing in Session on login action and delete on logout. The order history is not stored there but pulled on demand. Can you give more details on HOW you check for authentication?
Michael D.
Oh. Assuming you're not doing anything crazy (like rolling your own authentication), check HttpContext.Current.User.Identity.IsAuthenticated . You can also get the username from Identity.Name.
James S