ASP. net mvc 4 SimpleMembership Provider (1)

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.