Multiple roles in 'User.IsInRole'

I have 3 roles on my page, so I want to access the link with two roles.

I'm trying something like this

@if(User.IsInRole("Admin,User")) 
{
 //my code
}

Or that

@if (User.IsInRole("Admin") && User.IsInRole("User"))

{
 //my code
}

Nobody works, the only one I managed to work with is:

 @if (User.IsInRole("Admin")

But this is the last for only one role, how can I do what I want?

+4
source share
1 answer

Nobody works, the only one I managed to work with is:

This is reasonable if you think the method does IsInRole.

Gets a value indicating whether the current user is in the specified role. The API is intended only to be called within the context of the ASP.NET request flow, and in this permitted use case it is thread safe.

Admin ( UserIsInRole("Admin") true), ( UserIsInRole("User") false). , User.IsInRole("Admin") && User.IsInRole("User") false.

:

// If the user role is either admin or user then do something
@if (User.IsInRole("Admin") || User.IsInRole("User"))
{
    //my code
}
+9

Source: https://habr.com/ru/post/1613739/


All Articles