Question

I have create a create User Wizard in ASP.NET and added an additional dropdownlist Role for each user.

I have used the function ,

 
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        DropDownList ddlRoles = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlUserRoles") as DropDownList;
        Roles.AddUserToRole(CreateUserWizard1.UserName, ddlRoles.SelectedItem.ToString());

    }

This creates a user and makes entry in aspnet_user, aspnet_membership table but do not create any entry in the table aspnet_UsersinRole table. I am joining these tables to get back required data but it is not giving desired result since for a user no entry exists in aspnet_UsersInRole.

Was it helpful?

Solution

Check you have roles enabled in the web.config, correct with your right connectionStringName

<roleManager defaultProvider="DefaultRoleProvider">
  <providers>
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
  </providers>
</roleManager>

OTHER TIPS

If you want DropDownList's selected value, you want to use SelectedValue.

Roles.AddUserToRole(CreateUserWizard1.UserName, ddlRoles.SelectedValue);

FYI: Please make sure you have created Roles in aspnet_Roles table in advanced. Otherwise, no record will be added in aspnet_UsersInRole table if the specific role is not found in aspnet_Roles table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top