Search code examples
rolesrazor-2asp.net-webpages

Razor 2 if user is not in one role or if user is not in another role


I'm trying to check if a user is in role "admin" OR if the user is in role "publisher", because both admin and publisher is meant to be able to post articles on my site. Every time I go to the Create-tutorial page as a Publisher, I just get redirected to the Members Dashboard. If I go there as admin, I can create articles just fine.

Here is my if-statement

if (!Roles.IsUserInRole("Admin") || !Roles.IsUserInRole("Publisher")) {
    Response.Redirect("~/Members/Dashboard");
}

Solution

  • @mclaassen answered my question in a comment, I'm now adding the answer to avoid this being unanswered.

    Change || to &&