0

[Authorize(Role=Role.Admin, Role.Client)] does not work yet, [Authorize(Role="Admin,Client")] works, I want to pass in strongly typed objects as I have them defined, does anyone know how?

I dont want to be hitting the database multiple times so something like:

[Authorize(Role=Role.Admin)] 
[Authorize(Role= Role.Client)] 
public ActionResult Something()
{

}

Is not ok for me...

EDIT:

Ok... so the previous question has been asked before, but I have amended, How do I create this as a delegate or function? I want to select one or more roles? Is this possible?

I could do:

[Authorize(x=> x.Role == Role.Admin && x.Role == Role.Client)]
Haroon
  • 3,402
  • 6
  • 43
  • 74

1 Answers1

1

Have a look at this blog post on how to implement a custom authorize annotation that takes an array of strongly typed role objects:

http://geekswithblogs.net/tyarmer/archive/2010/02/25/strongly-typed-roles-in-mvc-with-authorize-attribute.aspx

Till
  • 3,084
  • 17
  • 18