ASP.NET MVC user in all roles

In ASP.NET, you can decorate the method as such

[Authorize(Roles="Moderator,Tester")]
Function ActionResult Foo()
{
   return View();
}

      

This will restrict access to users who are in one of the specified roles.

I have a requirement where the user should be in all specified roles. I can create a new role for this; But I was wondering if it is possible to decorate such a method so that the user is part of all specified roles?

Is this possible with an attribute Authorise

or do I need to create my own?

+3


source to share


1 answer


Just use the attribute [Authorize]

multiple times:

[Authorize(Roles="Moderator")]
[Authorize(Roles="Tester")]
Function ActionResult Foo()
{
   return View();
}

      



This will require the user to be in both (or more) roles.

+4


source







All Articles