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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |