Keith
November 10, 2025, 1:46pm
1
Is there a way use declarative validation to check whether user has either of 2 roles?
I would like to define something like the following on a service model:
// Either role is valid for access
[ValidateHasRole([UserRole.ReadData, UserRole.ViewData])]
In the ServiceStack documentation, ValidateHasRole requires ALL roles:
[ValidateHasRole] Protect access to this API to only Users assigned with ALL Roles
so, the folowing would also require BOTH role
[ValidateHasRole(UserRole.ReadData)]
[ValidateHasRole(UserRole.ViewData)]
mythz
November 11, 2025, 12:49am
2
You would have had to [RequiresAnyRole([UserRole.ReadData,UserRole.ViewData])] Request Filter attribute on your Service class (i.e requires reference to ServiceStack.dll).
I’ve just added support for the impl-free ValidateHasAnyRole attribute which you can add on your DTOs instead:
[ValidateHasAnyRole([UserRole.ReadData,UserRole.ViewData])]
This change is available on v8.9.1+ that’s now available in pre-release packages .
Keith
November 11, 2025, 6:34am
3
Great, thank you for the information and the enhancement. Much appreciated.
1 Like