The new ASP. net mvc 4.0 provides a new Membership Provider called SimpleMembership.
First, we create a new solution.
First, let's take a look at web. config.
Visual studio 2012 LocalDb. to connect, use (LocalDb) \ v11.0 as the Server name
Open the Web. config file and add the content.
Open AccountController. cs and find the class UserProfile.
For example, we add a custom attribute named Address,
Because we use code first, at this time, we need enable-migrations
After completion
After opening Migrations \ Configuration. cs, you can see that the automatically generated class code is like this.
At this time, we need to modify the content
First, we reference
Modify the following code
Note that!
This must be changed to true.
Then run update-database-verbose on the Package Manager Console to modify the database.
Now let's check the database status.
We can see that the user and role of init in Code First are already in the database.
At this time, we run the entire web program and use the user/password, manager1, and password we have defined before.
We can see that we have logged in to this website.
Okay. Let's test the Role function.
If the current role is Admin, a secret information will be displayed on the Index page.
Open Views \ Home \ Index. cshtml
Add the following code:
Successful!