Authorization .net 5 in serenity framework

633 Views Asked by At

Can someone show how to get current logged user? And how to chek his permissions, because this doesn't work?

var user = (UserDefinition)Authorization.UserDefinition;
if (!Authorization.HasPermission(PermissionKeys.Tenants))
query.Where(fldTenantId == user.TenantId);

Thank you!

1

There are 1 best solutions below

0
Rendition On BEST ANSWER

The easiest way is to use the Context object

to get the user id Context.User.GetIdentifier()

to get the user name Context.User.Identity.Name

To get the permissions you can use: Context.Permissions and Context.Permissions.HasPermission