3
votes

Though I asked few questions about the how to use membership providers with ASP.NET MVC 4 but hardly got any response. It is taking me time (as a newbie) to get started with membership providers in ASP.NET MVC 4. I have been reading article, trying stuff but that only added to the confusion rather than helping.

What would be the answers to the following queries by a beginner:

  1. I want to try all the membership providers (including the simple membership provider) before deciding which one should I use for which project. What membership providers can I use with ASP.NET MVC 4 and How can I configure each one of it. Any documentation or links?
  2. Though the internet template comes with pre-configured Account controller which sets the membership functionality, but how can I add membership functionality to the basic template. What steps should I follow in order to configure membership using membership providers (I assume there will be different set of steps/configuration/settings for different membership provider).
  3. Running the ASP.NET MVC 4 project created with internet project template (without making any changes to it) create 5 tables in the database namely UserProfile, webpages_Membership, webpages_OAthMembership, webpages_Roles, webpages_UsersInRoles). In AccountModel.cs I see definition for only one, UserProfile. Where are the other tables defined. Do I always need to have all these tables in database in order to use membership. Can I customize them, rename them or choose not to use some of them?
  4. I do not see any membership configuration in web.config for the internet project template yet is using membership. In some of the articles tutorial I saw people configuring it by adding <membership></membership> to web.config. When do I need to add configuration settings to web.config and when do I need not?

I think membership providers are meant to make developers life easy yet for me it is making it more difficult. I know I really need to study it and that's what I am trying for the last 7, 8 days but unable to figure out. Any help, links (hopefully not those which I went through many times) are more than welcome.

2
but these are practical, answerable questions based on actual problems that I face and they are closely related and an answer to one can answer another at the same time.ZedBee

2 Answers

3
votes

I agree with you, the guidance around what membership types do what just sucks.

  1. You can use any of the providers with ASP MVC. The default template in Visual Studio that is the Internet MVC app is the only one that uses SimpleMembership.

  2. Good question, I've not found any explicit, decent documentation on that at all. As far as I can tell most of the membership things are setup very similar.

  3. At least SimpleMembership will create the needed DB tables that are required if they do not exist. I think the only one you can really customize is your user table.

  4. I think like the sql tables, the membership tags in the web.config are implied. If you accept the defaults they magically work.

Best link I've found is this http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properties/

In that post there are two others that are helpful as well.

1
votes

For question 3, I tried something and it turned out that:

Yes: You can add new columns to UserProfile (and all other tables, I guess)

No: You cannot rename the table, even if u have modified the codes in AccountModels to match new table names. In this case, a set of tables with old names will be created again when you launch application. And all codes provided by MVC4(MembserShip, WebSecurity, Users, Roles....) will used the old tables.

And, I have never found any information about how to rename these tables.