How to check if some user is in the role


I want to build Administration panel in which I could controll which users are in selected role. I'm writing it in ASP MVC, but it doesn't matter. 

First I'm checking is edited/managed role exist (if no I'm writing message):


if (Roles.RoleExists(roleName))
ViewData["Title"] = "Manage users in role: " +roleName;
ViewData["roleName"] = roleName;
MembershipUserCollection users = Membership.GetAllUsers();
return View(users);

  and in the view I want to show list of all users with checkbox indicating if user is in selected role. Here I have problem. There's method Roles.IsUserInRole(roleName) but it check only currently logged-on user. There's also Roles.FindUsersInRole(roleName, user.UserName) which return in my case empty string[] (I have users in that role). I can't also understand why it return strings array not bool true/false.

When you go to ASP.NET Configuration->Security->Manage Roles->Manage (on selected Role name) there's what I want. I found in source code manageSingleRole.aspx what I want:


RoleHelperInstance.IsUserInRole(userName, currentRoleName)



(bool)CallWebAdminHelperMethod(false, "IsUserInRole", new object[] {(string) DataBinder.Eval(Container.DataItem, "UserName")

  I want exactly that kind of method, returning true/false with two values on input: userName and roleName. How can I use RoleHelperInstance, where can I find source code. I would be grateful for any other solution.

Best regards

Don't forget to click "Mark as Answer" on the post that helped you.
3/29/2009 3:07:53 PM 27051 articles. 1 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 24
Get it on Google Play
Get it on Apple App Store

 Of course, five second after post I found solution. I tried once Roles.IsUserInRole(user.UserName, roleName) but then I got some error messages. Now it's working..

Best regards

Don't forget to click "Mark as Answer" on the post that helped you.
3/29/2009 3:31:08 PM

Similar Artilces:

Creating User Account Without Default Security Role (Registered User Role)
  My DNN version is 3.1.1. The portal is set to Private Registration. Unauthenicated users have access to the basic pages of the site. We require my company's current customers to register and be approved to have access to all other pages that contain information restricted to them (the major part of the site). As you know, authorizing a user account applys the Registered User security role by default and this is how I control access to the customer areas.  We want to create a page that will be used by Marketing to allow potential customers by login to...

How do I check whether a user is in a role when the user is not yet authenticated
My problem:  Users coming through a portal are automatically authenticated as guests, using a standard password that nobody ever sees.   However they can also register as normal users, in which chase they have their individual password which they know, and the usual functions to reset their password, handle a forgotten password, and so on.So, in my register-from-portal code, after recognizing that this is a returning user we need to authenticate the user: but we don't know whether to use the standard portal password, or request an individual password.  I would like to writ...

Check if user is in role
Hello,I need to check if a user with a certain username is in a specific role.This is not the current user which is logged on.How can I do this?Thanks,Miguel UserIsInRole();CheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question! Visual Basic If User.IsInRole("members") Then buttonMembersArea.Visible = True End If C# if (User.IsInRole("members"))  { buttonMembersArea.Visible = True; You might want to have a look at this:

Check user role
How do you check to see if a user is member of a particular role created in DNN? I've tried using: If PortalSecurity.IsInRole("Production") = True Then... and also If context.User.IsInRole("Production") = True Then... but neither of them seems to work. Weird thing is I believe one of the two code used to work but doesn't seem to. Thanks. I believe that IsInRole() takes the RoleId as a string parameter, not the RoleName.~ChrisNet Data

How to check user role
I'm creating a module that I want to display certain things to specific roles. How do I check the roles of the currently logged in user? Sorry if this is a newb question but really not sure how this is done. ThanksCheersmidspot Hmm - you can use PortalSecurity.IsInRole to check if the logged on user is in a specific role or array of roles.. or                 RoleController roleController = new RoleController();                 roleController.GetUserRolesByUser...

RSA Secure ID enabled website along with role based access to the RSA Secure ID Users
Hello All, I am trying to implement RSA Security to my intranet website. I want to access the 'RSA Secure ID User Name'  and 'Password(Passcode here if possible)' in my application to set the roles of the user in the website. I want the RSA Secure ID user as my website user if it is registered into my database only. It means 'RSA access' and 'allocating the page access rights' to the user is totally depends upon the 'secure Id user' . I have to retrieve this information from RSA server and use it into my applic...

Duplicate Security Roles Showing up In Security Roles Manager
Anyone have any ideas?  We have had and instance of 3.0.13 with one child portal running for about a month now.  A few days ago our adminstrator noticed that we have duplicate entries for security roles. For example, the Security Roles Manager shows:Name Description Fee Every Period Trial Every Period Public Auto   Administrators Portal Administration         False False   Administrators Portal Administration         False False  Registered Users Registered Users    &n...

Manage Users For This Role / Manage Roles For This User Question
In the roles/user management pages there is a link called Manage Users For This Role and Manage Roles For This User respectively. I want non Admins to be able to see these pages, and currently I have it so that they can see the manage users and manage roles pages. However, when a non admin clicks on Manage Users For This Role or Manage Roles For This User link it does not display the control, just an empty page. I can get around this by giving edit rights to the page, but I do not want them to have edit rights for the page. Any ideas? Thanks  ...

How to check user role membership?
Is it possible to determine the user roles for a login other than oneself? sp_displayroles works, of course, but I want to do something programmatically. And select is, by default, denied on the role tables even when logged in as SSO. Basically, I want to do something like: if USERID is not granted to SOME_ROLE then do something But I don't see any way to do this unless I'm logged in as USERID. Thanks, Mike You can do check in the sysroles table if exists (select * from master.dbo.syssrvroles where name = @name) Thanks ...

Checking what security group a user is in
Hi Guys I am building an intranet application for our local win2k3 server, I have created a security group under active directory called WebAdmin and added the appropriate users. I now need to set a session variable in the global.asax file for use later in the app. I think I am close but not close enough the following code doesn't seem to work If User.IsInRole("WebAdmin") Then Session("AdminRole") = "Approved" Else Session("AdminRole") = "NotApproved" End If My authentica...

IF statement (check if user is in a role)
Is it possible to write an IF statement that checks that the user is in a certain role? (using the VB language) If Roles.IsUserInRole("Username", "RoleName") Then End IfJared RobertsLead Application Developer...

How to check roles of a selected user?
 I was following a tutorial on the site about Assinging Roles to User (aspnet_tutorial10_AssigningRoles_cs). On the "Checking the Roles the Selected User Belongs To" step, it has this code:  1 private void CheckRolesForSelectedUser()2 {3 // Determine what roles the selected user belongs to4 string selectedUserName = UserList.SelectedValue;5 string[] selectedUsersRoles = Roles.GetRolesForUser(selectedUserName);6 // Loop through the Repeater's Items and check or uncheck the checkbox as nee...

Security Roles and User management
I have a question concerning Sercurity roles in 2.0 beta 3. I noticed that I am unable to delete the registered security role from user profiles where as I was able to do this in 1.x will this be the same in the final release? I ask because I would really like to set up 3 security roles just like I currently have in 1.x: Public - no rights other then read ony Registered - allowed to make content changes but not move modules or add users and such Admin - full control Will this be possibe in 2.0? This is kind of a criticle issue for us as we are going to be using DotNetNuke f...

Is user in role check failed!
Please help! I have interface on my page based on users role.I check it by following code:      If Roles.IsUserInRole(Profile.UserName, "Admins") Then                Me.TextBox1.Text = "adm"     End IfAnd this check fails: I log in like "administrator", LoginStatus control indicates that I am logged in and I am administrator user.But my textbox shows otherwise!!!I checked if the user is in role through ASP.NET defauld site administration tool. It is...

Web resources about - How to check if some user is in the role -

Check the Weather
provides weather data across the globe. From Timbuktu to Istanbul, wherever you end up you’ll always know what it’s like outside.

Check Point - Wikipedia, the free encyclopedia
Check Point Software Technologies Ltd. is an international provider of software and combined hardware and software products for IT security , ...

Facebook Reminds Page Admins to Check Their Post Attribution Settings
Facebook page administrators are seeing pop-up messages reminding them to “change attribution settings” and ensure that they are posting as their ...

WA death in custody inquest: No temperature check before WA woman Ms Dhu died
Two nurses who saw a woman in custody the day before she died failed to check her temperature and attributed her tachycardia to drug withdrawal ...

Parents to get random 'spot checks' on their work hours under new Coalition childcare plan
Families will be subjected to random "spot checks" from the government to make sure they are reporting their work hours accurately ...

There Are $2.3B In Unclaimed Funds In Ohio: Here's How To Check If You're Owed Money
... of Commerce Division of Unclaimed Funds says unclaimed funds are money or the right to money that may have been dormant in bank checking or ...

Some of Tesla's Model S recall checks are pretty lo-fi
Filed under: Green , Recalls , Videos , Tesla , Safety , Sedan , Electric , Luxury A Tesla owner demonstrates the lo-fi check for the potential ...

Check out the highest-rated comment on this WaPo column, "The American Dream? I thought so, until I had ...
"Just another first world, entitled diatribe. What??? You had to cut cable and drive an older car and only eat out once a week? The horrors!!! ...

Colorado: Expanded Background Checks, ‘High Cap’ Mag Ban, High Profile Shootings
Colorado: Expanded Background Checks, 'High Cap' Mag Ban, Mass Shootings

Check out the insane way Taylor Swift thanked her 125 crew members
With only a handful of dates left on her marathon world tour for "1989," Taylor Swift gave her crew a few days off. But in typical Swift fashion, ...

Resources last updated: 12/2/2015 11:59:02 PM