Check User exists in a Role in ASP.NET Identity 2.0

Read full post on Falafel blog

ASP.NET MVC5 uses Identity 2.0 to manage the users and their roles. There may be scenario to check whether the currently logged in user or any user with the id exists in the given role or not, and checking can be done either in the controller class or in any other class of the application.

Check for the currently logged in user
In a controller you can find whether the currently logged in user exist in a role or not by using User property of the controller class. Type of the User property is IPrincipal and it has a Boolean method IsInRole which takes the role name as input and returns true if the currently logged in user exist in the role.

Read full post on Falafel blog

Leave a comment

Create a website or blog at WordPress.com