Membership and Roles - allowing user to choose a role provided by the developer rather than employing Roles.GetAllRoles(); method

Hi all,

 

Is there a way to allow the user choose a role from a selection you provide them with? e.g. I have 3 types of users: admin, contractor, and landlord. Of course I don't want them to be able to assign themselves admin role, so how would I proceed? (I'm using C# by the way)


This is what I have so far. Please note "Roles...();" is where I am stuck:


-within my aspx page i have:

<asp:WizardStep ID="CreateUserWizardStep2" runat="server"

Title="Contractor or Landlord?">

<asp:ListBox ID="ListBox1" runat="server" OnActivate="ActivateStep" OnDeactivate="DeactivateStep"></asp:ListBox>

</asp:WizardStep>


-within my codebehind:

public void ActivateStep(object sender, EventArgs e)

{

ListBox1.DataSource = Roles...();

ListBox1.DataBind();

}

public void DeactivateStep(object sender, EventArgs e)

{

Roles.AddUserToRole(User.Identity.Name, ListBox1.SelectedValue);

}

 

Thanks in advance!

0
domesticmonkey
3/22/2008 10:21:19 PM
asp.net.security 27051 articles. 1 followers. Follow

4 Replies
848 Views

Similar Articles

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

Roles.GetAllRoles(); method will return a string array filter it to exclude the 'Administration' role and let its name be configurable in case you change it later and then bind the new string array to the ListBox.


Hosam Kamel

Remember to click on Mark as answer on the post that helped you
0
HosamKamel
3/22/2008 11:00:52 PM

Hi HosamKamel,

I understand what you mean, but how would I filter it and "bind the new string array to the listbox"? Code would really help, as I'm new to ASP.

 

Thanks again! 

0
domesticmonkey
3/22/2008 11:19:29 PM

domesticmonkey:

Hi HosamKamel,

I understand what you mean, but how would I filter it and "bind the new string array to the listbox"? Code would really help, as I'm new to ASP.

 

Thanks again! 

 

Just loop for your string array length and compare the values and then add the none administration values to another sting array and then bind values

  string[] newCollection = new string[allRoles.Length-1];
            for (int i = 0; i < allRoles.Length;i++ )
            {
                //compare role
                //if not admin add it to the newCollection
            }

            ListBox1.DataSource = newCollection;
            ListBox1.DataBind();

 


Hosam Kamel

Remember to click on Mark as answer on the post that helped you
0
HosamKamel
3/22/2008 11:38:25 PM

I found an easier way, though it kinda contradicts the meaning of this thread subject.

 

Before binding all the roles from to a list box, I merely removed the role in question with: ListBox1.Items.Remove("Admin User"); 

0
domesticmonkey
3/23/2008 11:03:18 AM
Reply:

Similar Artilces:

Roles, roles, roles
Hey is it posible o have a role for a user to only update the content? I don't want that user to change skins or to make other admin changes... up I think if you allow a role to edit contents on a module level he wont be able to change anything else. Did you try that? cheers, erikErik van Ballegoij, The Netherlands if you allow a role to edit contents in a module lets say discussions module, then that role will be able to edit, delete the threads. so for a role to be able to add new thread only, do we need to write our own code?-keeara g------------------ keeara, see...

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...

Role methods on roles, not classes
Hi all,=0A=0AThis problem is annoying and I'm not sure of the best approach= ..=0A=0ALet's say I have a list of roles and an object and I want to seriali= ze the object as XML. Imagine the following (this is my actual use case):= =0A=0A sub to_xml {=0A my $self =3D shift;=0A my $xml =3D ''; # = string XML sucks. Just an example :)=0A foreach my $role ($self->meta-= >roles) { # or whatever it's called=0A next unless $role->meta->does= ('DoesXML');=0A $xml .=3D $role->as_xml($self); # method available o= n the role ...

Roles
I'm using a CreateUserwizard control and in the code behind for CreatedUser event I am trying to add the following single line of code:  Roles.AddUserToRole ... etc. However, Intellisense does not show Roles. (I am seeing RoleServiceManager but not Roles) Any idea why? I have Visual Studio 2008 and the project is targeting .NET Framework V3.5. Also, I have <roleManager enabled="true"> in the web.config file. Intellisence will work automatically, There is no relation to web.config, if any problem use,using System.Web.Security; ...

Membership and Role Management
Hello, I've configured SQL server 2005 as my back-end data store via aspnet_regsql.exe. I presume it was succesvol. Creating users en roles programmatically is no problem. When I start the Web Site Administration Tool I can see the created users and roles. But when I want to show them by code I get an empty result. ... ... Roles.GetAllRoles()...... membership.GetAllUsers() The roleManager is enabled in web.config.<roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSS...

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  ...

Extending role, personalization and membership features when a user can assume multiple roles
I have a tracking project to work on and I intend to use VWDE for it.The salient features of the system is that a user can be a participant in multiple projects and he can assume different roles in different projects. He can, for example be an analyst in one project, a project manager in another and yet again, a tester in another one. Now, depending on what role he is in a project, he will be granted the appropriate privileges. For example, as a Project Manager, he can track the progress and view and approve documents submitted by members of his project team, but as an analyst, he can just s...

Windows Authentication
 I have an app with Windows Authentication and a customer sql role prvovider. I check if a usrs windows account exists in my database and populate a list of roles.Issue is how do I handle if user has no roles and I should deny access. I thought my 401 catch all in the errors section on my config would redirect to an error page. But my code goes in a constant loop.How do I redirect a user to an access denied page when I have a role provider setup in the web.config? HI,mindgmz mindgmz:Issue is how do I handle if user has no roles and I should deny access. I thought my 401 catch all in t...

Regarding Roles and $?ROLE
Hello all. I have some questions about how Roles will behave in certain instances, and when/where/what $?ROLE should be bound too. 1) Given this example, where 'bar' is a method stub (no implementation) role Foo { method bar { ... } } Should the eventually implemented method still have a binding for $? ROLE? 2) When a Role itself has subroles, which are composed together and consumed by the parent Role, how is $?ROLE bound? is it the top-most Role which it is bound too? or is it bound to the Role it originally came from? Here is an example: role F...

Roles and Sub Roles
I was wondering if anyone has ever had an instance for needing Sub Roles in a Role Manager.  Here's an example: Office Type #1 (Main Role) Accounting (Sub Role) Office Manager (Sub Role) Office Type #2 (Main Role) Accounting (Sub Role) Janitor (Sub Role) Both office types are sole and separate roles as well as both Accounting sub roles.  Does anyone know of a way to do this using .NET's Role Manager?  I'd rather keep it that way because the application is already written and this change just came in towards the end of the project.  Thanks, ...

Roles within roles
Hi, Is there a way to have a role within a role? Basically I want something similar to Windows groups, where you can have a group within a group and so on.For example, can I have the following structure in .NET membership (each node is a role)- ITDepartment    - Managers    - Technicians       - Level 1       - Level 2 - Lecturers    - Science    - Business    - Computing- OtherStaff    - Admin    - Caretakers  Hi The b...

How to know role membership from role name
I created some new roles and need to check whether a user is a particular role or not. I look all around the core classes but cannot find any function to do so. Is there a way to know is a user is in a role based on ROLE NAME? You must use the Admin, User Accounts. Then select the user in question, after which select Manage Security Roles... Hope this is what you are looking for.~ChrisNet Data Design706Horsman.us Well, I mean in code. I'm developing some new modules which will check for a user being in a specific role to allow for some actions. So I need to check if "Use...

Delete Roles how affect Users in that roles
Dear all,  I know that Roles.deleteRoles(e.command.arguement). If deleted the roles, how the users if they belong to that roles. Would their roles also be dropped? I mean if looping the user roles. What will be the result. hi the delete will fails if there is a usrs assigend to the role , so before you want to delete the Role, you should remove the users from that role ,by using Roles.RemoveUserFromRole(UserName,RoleToDelete)   http://msdn2.microsoft.com/en-us/library/aa478950.aspx http://forums.asp.net/p/1181608/2004433.aspxRegards,Anas Ghanem.Note:Please Don't hesi...

Roles.GetAllRoles Hide one Role
Hey guys...  Roles.GetAllRoles(); list all roles in the DB thats fine.. But i wanna leave out "admin" How can i remove that from the function?    var roles = System.Web.Security.Roles.GetAllRoles(); var allRolesButAdmin = roles.Where(x => x.ToLower() != "admin").ToArray();All that glitters is gold-Only shooting stars break the mold. The GetAllRoles method calls the [dbo].[aspnet_Roles_GetAllRoles] stored procedure. If needed, you could modify this query with a simplw WHERE clause to exclude your desired role.Thanks, EdMicrosoft MVP - ASP/...

Web resources about - Membership and Roles - allowing user to choose a role provided by the developer rather than employing Roles.GetAllRoles(); method - asp.net.security

Resources last updated: 12/21/2015 1:10:34 PM