Sunday, 30 December 2012 13:56

how to assign specific role when user registers

Written by 
Rate this item
(0 votes)

using asp.net membership provider user
registration is done by the CreateUserWizard
control in the Register.aspx page.

what if we want to assign a specific role to
the user when they registers.It can be done
easily by adding OnCreatedUser event in the
CreateUserWizard control first -

<asp:CreateUserWizard ID="CreateUserWizard1"
runat="server" CreateUserButtonText="Next"
OnCreatedUser="CreateUserWizard1_CreatedUser">
.....

then we have to add the following lines in the
CreateUserWizard1_CreatedUser method in code
behind file-Register.aspx.cs as shown below -

protected void CreateUserWizard1_CreatedUser
(object sender, EventArgs e)
{
Roles.AddUserToRole(CreateUserWizard1.UserName,
"registered");
}

here i assigned the role 'registered' to the user.

Read 2650 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.