Login controls - assign a role to a new user or change a registered user's role

Hi

I'm building a web app in visual studio 2005 and I'm setting up a 'create user' page for the admin part of the app.

I'm creating a customised CreateUserWizard so that I can add a user to the asp.net membership list (in database on my server) and also add some info to one of my tables (user first name, faculty they work for etc).

 
I want to be able to let the admin user allocate roles (those already defined in my config) from a drop down list. I want to inculde this in my create user wizard, and have an 'update user' section where I can change their role there too.

 
Anyone have any ideas on if this is possible (sure it is somehow) and if so, how can I do it?

 
Thanks, Dave
 

0
dhassen
7/12/2007 10:09:01 AM
asp.net.security 27051 articles. 1 followers. Follow

6 Replies
1208 Views

Similar Articles

[PageSpeed] 13

Hi,

Well offcourse you can change the Role of the user. Well you can do somthing like this

string[] roles = Roles.GetRolesForUser(user.Username);
Roles.RemoveUserFromRole(user.Username, roles[0].ToString()); //If you want to remove the user from any particular role
Roles.AddUserToRole(user.Username, user.Role);

in the above code user is my own object that holds information for the user. You can use your own object here or simply place UserName as string.

Hope it will help you out,

Thanks and best regards,


Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
0
farazsk11
7/12/2007 12:47:54 PM

 thanks for the reply but I don't understand your example. I'm coding in vb but im using visual studio. 

I've added the ASP.net membership and roles database schemas to my database using aspnet_regsql and I created 4 roles using the configuration manager (the web interface one).

I'd like my createUserWizard to include a drop down list, listing the roles that are stored i my database, and assign them to the user when they are created. And be able to select the role from a drop down list when i need to change their role / account for whatever reason. I'm a beginner, so that's why I don't understand your reply, not detailed enough!

 

Thanks anyway
 

0
dhassen
7/12/2007 1:34:42 PM

 To others that might be interested, I found exaclty what I wanted here:

 

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx 

 

 

0
dhassen
7/12/2007 2:52:33 PM

Hi,

Well let me explain the code which I wrote above.

string[] roles = Roles.GetRolesForUser(user.Username);
Roles.RemoveUserFromRole(user.Username, roles[0].ToString()); //If you want to remove the user from any particular role
Roles.AddUserToRole(user.Username, user.Role);

In the above code Roles is a static class provided by .Net Framework 2.0 which is used to deal with the Role Management. GetRolesForUser is a method of Roles which returns the list of user (One user may belong to multiple roles). You can get the list of roles of a user as string[] roles = Roles.GetRolesForUser(strUserName); where string[] roles is an array of list that will store the roles returned by the method. Roles.GetRolesForUser(strUserName); I have just called the method GetRolesForUser with a user name passed an argument.

Roles.RemoveUserFromRole(strUserName, strRoleName); This method is used to delete a user for particular role where strUserName is the name of the User and strRoleName is the name of the Role from which the user I required to be deleted. This is only required when you actually required to delete a user from a particular role as in my case my user can only belong to one role.

Roles.AddUserToRole(strUserName, strRole); This method is used to add a user to a particular role where strUserName is the namd of the User and strRoleName is the name of the Role in which the user is required to be added.

If in your application a user can bleong to only one role then you have to first get the current role of the user, delete the user from that particular role and then add the user to the new specified role with the above mentioned methods.

I hope it will be clear to you now, incase if you still have any problem in understanding then advise.

Thanks and best regards,


Faraz Shah Khan
MCP, MCAD.Net, MCSD.Net, MCTS-Win/Web, MCPD-Web
Blog
0
farazsk11
7/12/2007 6:42:55 PM
I need to do almost exactly what you just described and the link you posted no longer works. Can you post what you did? Thanks.


Scratch the last; it doesn't work in Opera...I had to copy/paste the link into IE...
0
joseph
7/25/2007 8:23:28 PM

I've just checked the link above and it doesn't seem to work anymore.

Go to here: 

 http://weblogs.asp.net/scottgu/
 

And search for "login controls" the first returned result is the one you want, brilliant site that :) 

0
dhassen
9/7/2007 10:03:13 AM
Reply:

Web resources about - Login controls - assign a role to a new user or change a registered user's role - asp.net.security

Registered mail - Wikipedia, the free encyclopedia
Registered mail describes letters, packets or other postal documents considered valuable and in need of a chain of custody that provides more ...

Facebook Studio Edge URLs Registered
On the same day that Facebook introduced its new Camera iPhone application, three domain names based on Facebook Studio Edge were registered ...

Vevo doubles registered user count since switching to Facebook-only login; CEO hints at further integration ...
Music video service Vevo has doubled its total registered users as a result of switching to Facebook-only login and adding more personalized ...

How many registered users does NYTimes.com have?
There are some updates to this page that haven't been applied yet because you've entered some data into a form. You can refresh this page to ...

PRINCE2® Learning Aid from QA. PRINCE2® is a Registered Trade Mark of the Cabinet Office. on the App ...
Read reviews, compare customer ratings, see screenshots, and learn more about PRINCE2® Learning Aid from QA. PRINCE2® is a Registered Trade Mark ...

All sizes - German-registered RV in Canada - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

A Tony Baroni Luxury Exclusive: The Oldest Registered Home in Hillsborough County, Florida - YouTube
12401 Calusa Lane Thonotosassa, FL 33592 MLS# T2712012 Description: Welcome to Mimosa Groves on 5 Acres of Peaceful Paradise located on Lake ...

Debtors likely to be arrested on entry into the UAE if cases have been registered
If there are cases registered the debt must be repaid in full before the case can be cancelled.

Paris attacker was registered refugee - AdelaideNow Search Search
THE holder of a Syrian passport found near the body of one of the gunmen who died in Friday night's attacks in Paris was registered as a refugee ...

To be or not to be registered for GST, that is the question?
There is much debate at present concerning Australia's GST system. There appears to be a movement growing to increase GST from 10 per cent to ...

Resources last updated: 3/15/2016 6:25:01 PM