With .NET 2.0 its all easy :)
Drag and drop a CreateUserWizard in your page and set the OnCreatedUser=CreateUserWizard1_CreatedUser
Add a Wizard Step as below
asp:WizardStep ID="AddRolesStep" Runat="server" AllowReturn="False" Title="Step 2: Assign User To Roles"
OnActivate="AssignUserToRoles_Activate" OnDeactivate="AssignUserToRoles_Deactivate"
with a Listbox or any control to display the roles
After that in code behind add
public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
// Create an empty Profile for the newly created user
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
// Save the profile - must be done since we explicitly created this profile instance
p.Save();
}
// Activate event fires when the user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Activate(object sender, EventArgs e)
{
// Databind list of roles in the role manager system to a listbox in the wizard
AvailableRoles.DataSource = Roles.GetAllRoles(); ;
AvailableRoles.DataBind();
}
// Deactivate event fires when user hits "next" in the CreateUserWizard
public void AssignUserToRoles_Deactivate(object sender, EventArgs e)
{
// Add user to all selected roles from the roles listbox
for (int i = 0; i < AvailableRoles.Items.Count; i++)
{
if (AvailableRoles.Items[i].Selected == true)
Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.Items[i].Value);
}
}
Also dont forget to add in web.config file
< profile enabled="true" >
<properties>
<add name="Email" />
</properties>
</profile>
else you will wonder which namespace to add for ProfileCommon, compilation error will show, you are missing reference.
That's it, a Create User with associating to roles are ready!!!
Thursday, October 4, 2007
Subscribe to:
Post Comments (Atom)
i dont see required information in this, r u planning to blog agai on this topic.........pls reply to my mail
ReplyDeleteInstead of creating a seperate wizard step, you can convert the create user wizard to a template, add a drop down for the roles and other controls for capturing profile data. Then in the CreateUserWizard_CreatedUser event, save the role and profile data for the user.
ReplyDelete