Simple Membership Provider - Entity Structure and Roles

I am trying to use the Simple Member Provider with MVC 4 as "as per book" as much as possible. Here is the current scenario:

- I used Jon Galloway's post on the topic here .

1) I know that this thing is connected through the Entity Framework. However, I noticed that when I added properties to the UserProfile class, they did not appear in the table automatically when it was created. Is this due to the fact that a database has already been created (tables were missing)? I manually added the fields, and it was functional, but it would be nice to know the "gotchas", which will cause the fields to not be automatically created.

2) As for the roles, it seems that it is focused primarily on the subject of a global type of rights (i.e. the user is the User, Administrator, etc.). In case you want it to be processed at the project level (i.e. admin for project1, user for project2), what changes need to be made?

etc.) Is there an article that really sets out in detail regarding best practices for expanding it?

+4
source share
1 answer

1) I found the UserProfile part of the Simple Membership table a bit complicated (in a good way), but it worked great for my applications.

A simple membership agreement is to create a UserProfile table named "UserProfile" with two UserId and UserName fields. You can configure a different table name or different UserId and UserName field names for UserProfile by changing the WebSecurity.InitializeDatabaseConnection () line in Filters / InitializeSimpleMembershipAttribute.cs. You can create a UserProfile table with additional fields, and it will be used by Simple Membership if the Simple Membership finds this table on first run. In the default configuration, the first time the application is started, SimpleMembership will create database tables, including any userProfile table data specified in Filters / InitializeSimpleMembershipAttribute.cs.

So, the trick is to create the desired UserProfile table (including all the fields you want in this table), before the first call to Simple Membership. This could be created using EF Migrations or created a script database or even created manually in SSMS.

If you want to enter a simple membership code, see http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/5cb74eb3b2f3#src/WebMatrix.WebData/WebSecurity.cs and http://aspnetwebstack.codeplex.com/SourceControl/ changeset / view / 5cb74eb3b2f3 # src / WebMatrix.WebData / SimpleMembershipProvider.cs .

2) I agree with your point of view on roles and global permissions. Perhaps you can use AddUsersToRoles and RemoveUsersFromRoles (at http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/5cb74eb3b2f3#src/WebMatrix.WebData/SimpleRoleProvider.cs ) to change user roles when logging in to the project they are using.

etc.). I don't know a good article about expanding simple membership, but in principle, Simple Membership extends the Extended Memberhip Provider, which expands ASP.NET membership. You should be able to jump to a suitable point.

EDIT in response to Robert's comment:

As a direct answer to the question of why the Entity Framework did not create columns added to the UserProfile class, this happens when the UserProfile table was already created by initializing SimpeMembership before the application for the specific table was launched. The reason is that SimpleMembership has a built-in UserProfile table definition that is used anytime SimpleMembership creates this table. The timing for creating a UserProfile table is important, so you need to make sure that the application-specific tables are created before starting SimpleMembership initialization.

+5
source

All Articles