Assign a role to a user when creating an asp.net account

I am still a student and I am learning C #. I have to make a small application in ASP.NET. The application must use roles.

So, I β€œlinked” MemberShip to my database (using the asp_regsql tool). Now I have all the asp tables, so everything is fine. I created 2 roles (Admin and Client) using ASP configuration tools.

My question is:

Is it possible to create a page (for example, Register.aspx) and pass the hide parameter on this page to set the user role during registration?

For example, I will have a RegisterClient.aspx page, and when the user creates an account on this page, the account will automatically be associated with the client role.

Is this possible or should I do it myself using the ASP configurator?

Thank you for your help!

+4
source share
2 answers

You can add this Roles.AddUserToRole (model.UserName, "roleName"); to a registered register management event handler.

+7
source

You have to do it yourself in the code for something like this in order to assign a role to the user: -

<asp:CreateUserWizard ID="CreateUser1" runat="server" Width="435" OnCreatedUser="CreatedUser" CreateUserButtonType="Link"> public void CreatedUser(object sender, EventArgs e) { Roles.AddUserToRole(CreateUser1.UserName, "Members"); } 
+2
source

All Articles