I did in a huge application that has many different permissions and different roles, something like the following [I don't have code here, so I'll just try to recreate it here):
First I implemented the SecuredPage class as follows:
public class SecuredPage : System.Web.UI.Page {
This will be my BasePage for all pages for which the user needs permissions to access. MandatoryPermissions are the permissions that the user MUST have to access the page, and OptionalPermissions are the permissions for which the user needs at least one of them to access the page. There is no need to use them on every page, because if you have MandatoryPermissions , it doesnβt matter if you have extra or not.
Permission is an enumeration:
public enum Permission {
And MyUser is an implementation of MembershipUser :
public class MyUser : System.Web.Security.MembershipUser { internal bool HasPermission(Permission permission) {
Then the only thing you need to do on your pages is to fill out the permission lists:
public partial class EditUser : SecuredPage { protected void Page_Load(object sender, EventArgs e) { MandatoryPermissions.Add(Permission.EditUser); } }
public partial class SearchUser : SecuredPage { protected void Page_Load(object sender, EventArgs e) { OptionalPermissions.Add(Permission.SearchUserByUsername); OptionalPermissions.Add(Permission.SearchUserByEmail); } }
OK, the search example was not so good, but I think you got the image.
The whole idea is that base.OnLoad(e); called just before access control, so you just need to fill out the permissions in Page_Load .
I'm not sure if this is the best solution, but I'm sure it helps :)