[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

How would I add a user to a role in asp.net? (c#)

I'm trying to add a user to a row with the role manager but can't get it to work.  I would like the admin to be able to add role to users as needed.  I can't figure the code out.

this is what I have.  I have a gridview with the name of the user in it, when they click the button it put the user name in a label that i would like to use to assign the row to with my dorpdownlist of Roles.


Membership.ApplicationName = AppName.Text.ToString();
Roles.AddUsersToRole(selUser.Text, atRole.Text);

Open in new window

0
bmanmike39
Asked:
bmanmike39
1 Solution
 
Dhanasekaran SengodanCommented:
Great question! The most simple answer is to use the Web Site Administration Tool ASP.Net provides: http://msdn.microsoft.com/en-us/library/yy40ytx0(v=vs.100).aspx

After getting intitial testing out of the way, you undoubtedly will want to do this programmically. You can do this by calling Membership.CreateUser() as follows:

   
Membership.CreateUser( 
       model.UserName,  
       model.Password,  
       model.Email,  
       null,  
       null,  
       model.IsApproved, 
       out createStatus);

Open in new window


Also refer this link : http://weblogs.asp.net/gurusarkar/asp-net-mebership-creates-two-users-in-aspnet-users-table
0
 
bmanmike39Author Commented:
Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now