4

I'm still a student and I'm learning C#. I have to make a little application in ASP.NET. The application has to use roles.

So, I "linked" a MemberShip to my database (with the tool asp_regsql). Now I have all the asp tables so it's ok. I created 2 roles (Admin & Client) with the ASP configuration tools.

My question is :

Is it possible to create a page (like Register.aspx) and in this page to pass a hide parameter to set the user role at the registration ?

For example, I would have a page RegisterClient.aspx and when an user create an account on this page, the account is automaticaly associated to the Client role.

Is-it possible or have I to do this by myself with the ASP configurator ?

Thanks for your help !

2
  • 1
    You have to do it your self on the code behind page, right after the user is register, you associate him the role. Its not that difficult. Commented Jan 19, 2013 at 9:09
  • possible duplicate of how to Assign roles to User while creating their account Commented Jan 19, 2013 at 9:10

2 Answers 2

7

You can add this Roles.AddUserToRole(model.UserName, "roleName"); to the onregistered event handler of the register control.

Sign up to request clarification or add additional context in comments.

Comments

2

You have to do it by yourself in code behind something like this 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"); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.