views:

93

answers:

2

I have an application in which a user can choose from different (learning)groups. User has only access to registered groups. When the user enters the site, he can choose (in a dropdown) which group he wants to see, so the complete site filters content related to that group. So every controller needs to access this global "group" object.

What is the best way to do this in ASP.NET MVC? I've thought about a BaseController or ActionFilters. Is there any other best practice?

I've build a WebForms application and there I used a BasePage so that any other page has access to the group.

A: 

Why not store the selected groups against the user's record in your data store? Then you can filter based on this when querying the data store for the content to display.

Using the asp.net Session will not store the users preferences between visits so this would not be a viable solution if you want their options to persist when they return to your site.

Russell Giddings
They are registered to the groups. So these are available and stored in the database. When users logon, the system queries on there groups and stores them in the session. I need to know where to put the code to set and get the session. So what's the best practice for MVC?
Steven
In this situation I'd be more than happy to go for a basecontroller class. If this is data that is going to be required on most controllers then the basecontroller makes sense as it encapsulates the call and supports the idea of not repeating code. An action filter doesn't seem like the right solution here. Action filters are generally used to modify the way in which the action is executed. Another option would be to write a utility class which encapsulates the call. This would result in less clean controller code though as you'd be repeating the call to the utility in many places.
Russell Giddings
A: 

TheUserDataEntity

I recommend to have an UserData entity -directly related to your AuthProvider by the user GUID- containing all this kind of data and treat it as well ; )

An entity is more structured and maintainable -and Uber flexible for reuse : D

SDReyes