Last post Sep 16, 2014 12:29 PM by steve_flynn
Sep 12, 2014 12:11 PM|steve_flynn|LINK
I need to reference roles for a user other than the current user, whilst logged into a web app. I'm looking for something like
If User("Username").isinrole then
Obviously, above syntax is incorrect and it won't take the username variable. Is there a way to achieve this? To reiterate, I am not interested in the roles for current user.
Sep 13, 2014 03:07 PM|hakenr|LINK
you have to ask the source of your membership/roles data. Are you using original ASP.NET Membership and Role Provider? If so you can use the Roles.GetRolesForUser() method:
string roles = Roles.GetRolesForUser(username);
Sep 13, 2014 03:23 PM|Rion Williams|LINK
This really will depend on the actual type of Membership that you are using for your site (e.g. the new Identity Model or the older ASP.NET Membership model). Generally speaking, this functionality is built-in to both models and will simply require
you to know the username of the account you want to see about.
For example the
Roles.IsUserInRole() method accepts a username and a particular role and will return a boolean indicating if the user is in that role or not :
If Roles.IsUserInRole("username", "rolename") Then
' Do something here '
Sep 16, 2014 12:29 PM|steve_flynn|LINK