You must Sign In to post a response.
  • Category: ASP.NET

    How do send this authorize[role=''] by passing parameter

    I want send parameter to authorize[Rolle= Parameter]. Our organization want send parameter with role wise it can be admin, user, sales, general manager. sales manager and so on. I want sent by parameter to only action result methods.. instead Role.Administrator, Role.UserWithPrivileges) by sending parameter.

    [AuthorizeEnum(Role.Administrator, Role.UserWithPrivileges)]
    public IActionResult ThePrivilegeZone()
    return View();

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class AuthorizeEnumAttribute : AuthorizeAttribute
    public AuthorizeEnumAttribute(params object[] roles)
    if (roles.Any(r => r.GetType().BaseType != typeof(Enum)))
    throw new ArgumentException("roles");

    this.Roles = string.Join(",", roles.Select(r => Enum.GetName(r.GetType(), r)));

    public enum Role
    Administrator = 1,
    UserWithPrivileges = 2,
    User = 3,
  • #769643
    Hi Chandrasekhar,

    Find the below link. It may help you.

    I hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."

  • Sign In to post your comments