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