1

I want to assign roles to users when I create them by using the ASP.Net user create wizard.

I followed the steps written in the following answers:

Adding roles to the 'CreateUserWizard'

and

ASP.net failing to add role to user

but I always got an error message (The parameter 'username' must not be empty. Parameter name: username ) and color in red the following line:

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

what is the problem?

Here is my behind code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Security;

public partial class Participant_ParticipantSignUp : System.Web.UI.Page
{
public DropDownList roleDropDownList;

protected void Page_Init(object sender, EventArgs e)
{
    roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList");
}

protected void Page_Load(object sender, EventArgs e)
{
    DataBind();
}

protected void ContinueButton_Click(object sender, EventArgs e)
{
    SqlDataSource2.Insert();
    Response.Redirect("addParticipant.aspx?Email=" + Request.QueryString["Email"]);
}

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

}

Thanks in advance.

Community
  • 1
  • 1
Marwa
  • 11
  • 3

0 Answers0