Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of roles for the currently logged in user

I want to know what roles a logged in user belongs to without having to check the user against all possible roles (i.e. using Page.User.IsInRole())

like image 378
lithelike Avatar asked Apr 07 '09 03:04

lithelike


People also ask

How do you find the current user role?

First off, we check that the user is actually logged in. If they're not logged in, they won't have a role assigned. If the user is logged in, we use wp_get_current_user to return the WP_User object. This provides us with a stack of information about the data and we can access their user role(s) via $user->roles .

How do I see user roles in WordPress database?

In cPanel go to phpMyAdmin menu in Databases section: Once there, select your WordPress database. NOTE: You can check the database name of your installation in wp-config. php file, line define ('DB_NAME', 'databasename');

How can get current user role in asp net core?

var user = new ApplicationUser { UserName = model. Email, Email = model. Email }; var userRoles = await _userManager. GetRolesAsync(user);


2 Answers

using System.Web.Security;

Roles.GetRolesForUser()  

Or

Roles.GetRolesForUser(String) if not targeting the currently logged in user.

like image 82
lithelike Avatar answered Sep 22 '22 15:09

lithelike


try this if you want to check the currently logged in user for specific role:

Roles.IsUserInRole("Admin") 
like image 20
alam.net Avatar answered Sep 20 '22 15:09

alam.net