如何测试用户是否在 ServiceStack 的服务实现中具有角色
How to test if a user has a role within a service implementation in ServiceStack
我知道我可以在我的服务上添加 RequiresAnyRole 或 RequiresRole 属性:
[RequiresAnyRole("Admin", "HeadChaperone")]
public GuestChaperoneResponse Delete(DeleteGuestChaperone request)
{
bool hasHeadChaperoneRole = ??
}
但是如果用户具有特定角色,我如何在服务实现中进行测试?
您可以通过以下方式检查服务中的角色:
GetSession().HasRole(roleName,AuthRepository)
我知道我可以在我的服务上添加 RequiresAnyRole 或 RequiresRole 属性:
[RequiresAnyRole("Admin", "HeadChaperone")]
public GuestChaperoneResponse Delete(DeleteGuestChaperone request)
{
bool hasHeadChaperoneRole = ??
}
但是如果用户具有特定角色,我如何在服务实现中进行测试?
您可以通过以下方式检查服务中的角色:
GetSession().HasRole(roleName,AuthRepository)