Forms authentication and role-based permission validation
From membership to Simplemembership to ASP. identity,asp. NET every time I change the component of authentication, I am even more disappointed. The only function of membership is that you can refer to its implementation, and its database creation and extension is really not useful.
When everyone cheers for ASP. asp MVC, the authentication component goes further: Simplemembership, in addition to the reference value of third-party verification, its primary key and intrusion into the domain model make it a device, and the ASP. Identity in addition to the third-party verification of the more complex, still no improvement. Remembering Simplemembership's support for code first gave me all kinds of trouble that I'm still breaking.
The net identity has been improved in code first, but not just a identityuser inheritance in terms of dependencies, but also with Identitydbcontext trying to engage my dbcontext, Do you know if I have dbcontext?
Fortunately, the core is still cookie-based, forms authentication has been available, so do not hesitate to take out forms+formsauthentication hacked simplemembership and ASP. These two goods let me to gamble countless times, at the risk of countless small white and pseudo-combat experts really small white spray danger I also must abandon. Also, be thankful that the core page of authority validation is still IPrincipal, and that using a custom RoleProvider can save permission validation from these two ribs.
1. Configure the Web. config
2. Refreshing user and role
3. Only need to roleprovider the 2 methods
4.IAccountService and Iuserrepo are used only for demonstration purposes, relying on injection pages to simply use factory static methods.
For the sake of demonstration, using admin login, we return admin permission.
5. Function Demo:
The thought that I did not rely on arbitrary testing of the domain Model, only external interface dependent controller, the heart is really comfortable. Login, exit, admin permissions control, too late, you can not run the demo it.
Demo: Click to download
Forms authentication and role-based permission validation