Reputation: 341
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.
Upvotes: 0
Views: 285
Reputation: 7301
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>
Upvotes: 2
Reputation: 62280
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.
Upvotes: 1