Forms authentication and role-based permission validation

Source: Internet
Author: User

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

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.