c# - How to determine if a user belongs to a certain group using ASP.Net Identity Framework 2.0 -



c# - How to determine if a user belongs to a certain group using ASP.Net Identity Framework 2.0 -

using new asp.net identity framework 2.0, trying determine list of users belong group.

the usermanager , rolemanager instantiated , right infos while debugging don't understand how utilize user.roles.contains.

var _listallusers = usermanager.users.tolistasync().result; //var _allusers = usermanager.users; var roletomatch = rolemanager.findbynameasync("myusermanager").result; foreach (var user in _listallusers){ var _listgroupadmincat = user.roles.contains((identityuserrole)roletomatch); }

there's missing in syntax.

first identityrole object:

var role = rolemanager.findbyname("myusermanager");

then users in role:

var usersinrole = role.users;

your question title asking different question though, how determine user in role. this, utilize usermanager this:

int userid = 5; string roletocheck = "myrole"; bool userisinrole = usermanager.isinrole(5, roletocheck );

it's worth noting in code posted using asynchronous functions incorrectly. either utilize them await keyword or utilize synchronous versions:

var rolesynchronously = rolemanager.findbyname("myusermanager"); var roleasynchronously = await rolemanager.findbynameasync("myusermanager");

c# asp.net asp.net-mvc asp.net-identity

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -