简体   繁体   中英

Pattern needed for page-level permissions

I have a custom membership implementation (users and roles), and I'm implementing permissions on a page-by-page basis.

For example, in the Customer page, I disable insert, edit and deletion operations in case the the role has view-only permissions. I do this on Page_Load.

My only concern is that these rules are splattered across multiple pages (which is really Okay, because these rules are coupled to their specific pages). But I would love to have them in one same class, if possible, which is something I could manage to do by passing a reference to the Page object and getting the controls through FindControl.

But I don't want to "reinvent the wheel" and I was just wondering if there's a pattern out there to try and experiment. Much appreciated.

Create a new class that inherits from Page , CustomerPage for example. In CustomerPage , add the permission functions you need. Since it inherits from Page , you can now change the applicable pages to inherit from CustomerPage instead of Page without any issues.

In those pages that inherit from CustomerPage , you can call the permission methods as necessary to lock down your pages' access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM