Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:53:56+00:00 2026-06-11T11:53:56+00:00

I’m trying to implementing a new permission based access approach for my MVC application;

  • 0

I’m trying to implementing a new permission based access approach for my MVC application; We have several Permission Group and each group contains a list of Permission. for example we have Invoices permission group which contains CreateInvoice,RemoveInvoice,etc permission keys.

In this approach each mvc Action should requires a specific permission for execution. I’m trying to do this through CustomAttributes, something like this :

public class InvoiceController : Controller
    {
        [RequirePermission(Permissions.Invoices.CreateInvoice)]
        public ActionResult Create()
        {
            return View();
        }
    }

To make it easier for developers to remember different Permission Groups and Permission Keys I’m trying to create a pre-defined list of permissions that should be a combination of permission group and permission key. but due to restrictions applied to using attributes arguments in C#
I couldn’t make it work yet. (I don’t want to make an extra large enumurator and put all permission keys in there)

my last try was creating an enumerator for each permission group and then define permission keys as enum constants in there :

public class PermissionEnums
{
    [PermissionGroup(PermissionGroupCode.Invoice)]
    public enum Invoices
    {
        CreateInvoice = 1,
        UpdateInvoice = 2,
        RemoveInvoice = 3,
        ManageAttachments = 4
    }

    [PermissionGroup(PermissionGroupCode.UserAccounts)]
    public enum UserAccounts
    {
        Create = 1,
        ChangePassword = 2
    }
}

As you can see we have a combination of codes here, the permission group key specified using a PermissionGroup attribute and permission key’s code specified as numeral code on each enum constant.

the RequirePermission attribute defined as below :

public class RequirePermissionAttribute : Attribute
{
    private Enum _Permission;

    public RequirePermissionAttribute(Enum Permission)
        : base()
    {
        _Permission = Permission;
    }
}

but the problem is that objects of type Enum could not be used as Attribute Arguments.

Any suggestion/idea is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:53:57+00:00Added an answer on June 11, 2026 at 11:53 am

    I’ve found the solution, the only thing needs to be changed is type of constructure parameter. instead of using Enum you have to use object :

    public class RequirePermissionAttribute : AuthorizeAttribute
    {
        private object _Permission;
    
        public RequirePermissionAttribute(object Permission)
            : base()
        {
            _Permission = Permission;
        }
    }
    

    Here is the complete code :

    /***************** Permission Groups And Keys *****************/
    public static class Permissions
    {
        [PermissionGroup(PermissionGroupCode.Invoice)]
        public enum Invoices
        {
            CreateInvoice = 1,
            UpdateInvoice = 2,
            RemoveInvoice = 3,
            ManageAttachments = 4
        }
    
        [PermissionGroup(PermissionGroupCode.UserAccounts)]
        public enum UserAccounts
        {
            Create = 1,
            ChangePassword = 2
        }
    }
    
    public enum PermissionGroupCode
    {
        Invoice = 1,
        UserAccounts = 2,
        Members = 3
    }
    
    /***************** Attributes & ActionFilters *****************/
    
    [AttributeUsage(AttributeTargets.Enum)]
    public class PermissionGroupAttribute : Attribute
    {
        private PermissionGroupCode _GroupCode;
        public PermissionGroupCode GroupCode
        {
            get
            {
                return _GroupCode;
            }
        }
    
        public PermissionGroupAttribute(PermissionGroupCode GroupCode)
        {
            _GroupCode = GroupCode;
        }
    }
    
    
    public class RequirePermissionAttribute : AuthorizeAttribute
    {
        private object _RequiredPermission;
    
        public RequirePermissionAttribute(object RequiredPermission)
            : base()
        {
            _RequiredPermission = RequiredPermission;
        }
    
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var permissionGroupMetadata = (PermissionGroupAttribute)_RequiredPermission.GetType().GetCustomAttributes(typeof(PermissionGroupAttribute), false)[0];
    
            var groupCode = permissionGroupMetadata.GroupCode;
            var permissionCode = Convert.ToInt32(_RequiredPermission);
    
            return HasPermission(currentUserId, groupCode, permissionCode);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to select an H1 element which is the second-child in its group
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.