I am learning .net mvc3 and I am very confused about how user authentication works and was hoping y’all could get me pointed in the correct direction. My application needs to have users and groups, each of with needs to store data beyond what is needed for just authentication. For example, my user object needs to be able to store phone, fax, and email data and whether they are the project manager or not. My group needs to store some other data about that group such as website.
I am using Entity for my other models.
Should I create models for my user and group and somehow link them with the membership authentication? Or is the type of thing built in somehow? Or do I need a custom membership provider?
Sorry if I seem ignorant. I have only been doing .net for a week.
I come from a Django background if that helps in the explanation.
Thanks!!
You can certainly use forms authentication and utilize the default aspnet_Users and aspnet_Roles tables to handle things like login accounts and the various roles that you might have for the site, and then assign the roles to the users. That’ll allow you to
[Authorize(Roles = "Administrators")]your controller actions to control who can do what. You could set up a “Project Manager” role at this level and assign that, if it makes sense to control the DB based on that designation. If not, you could put that information in your own table.In my case I needed to associate data with users and so I created an application-specific Users table in my own database and then linked the aspnetdb Users table row for a user to the application’s Users table by adding a Guid column to my own Users table and populated that with the UserId from the aspnet_Users table data. That way when the a user logged into the system, I could retrieve the appropriate data (e.g., “My recipes”). There may be different/better ways to solve this problem, but that’s what I ended up doing for my own situation. In my application’s db, I just created my own tables to handle things like your Users and Groups since there were quite a few fields of interest. I didn’t want to alter the tables in the aspnetdb at all. I’ll be interested, however, to hear what other folks think.
You can see a question I posted about this subject here.