ASP. net mvc series: Forms authentication and Role-based permission verification, mvcforms

Source: Internet
Author: User

ASP. net mvc series: Forms authentication and Role-based permission verification, mvcforms

From Membership to SimpleMembership to ASP. NET Identity, Every time ASP. NET changed its authentication component, I was even more disappointed. The only role of Membership is that you can refer to its implementation. Its database creation and expansion are truly unusable.

When everyone cheers to Make ASP. when asp mvc is developed, the Authentication Component goes further: SimpleMembership, in addition to the reference value of third-party authentication, its primary key and intrusion into the domain model make it a decoration, while ASP. in addition to making third-party authentication more complicated, NET Identity still has not been improved. I think of the troubles that SimpleMembership has brought to me in code first support.

ASP. NET Identity has been improved in the Code First aspect, but it is not only an inheritance of IdentityUser in terms of dependency, but also uses IdentityDbContext to try to implement my DbContext. Do you know if I have DbContext?

Fortunately, the core is still based on cookies, and Forms authentication can be used all the time. Therefore, we do not hesitate to use Forms + FormsAuthentication to kill SimpleMembership and ASP. NET Identity. These two items have made me bet countless times over the past two years, and I have to discard them even if I am at risk of being sprayed by countless experts, such as Tom and Tom. Fortunately, the core page of permission verification is still IPrincipal. Using a custom RoleProvider, you can save permission verification from these two vulnerabilities.

1. Configure Web. config

2. Refreshing User and Role

3. You only need to set the RoleProvider of the two methods

4. IAccountService and IUserRepo are only used for demonstration. The dependency injection page uses the static method of Factory.

For ease of demonstration, if you use admin to log on, the admin permission is returned.

5. Function Demonstration:

I am very comfortable thinking that I don't have any Domain Model that relies on arbitrary testing and only the Controller that the external interface depends on. It's too late to log on, exit, and control admin permissions. You can't run the Demo yourself.

Demo: Click to download

 

Related Article

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.