ASP.Net无法在创建用户向导

时间:2016-10-17 19:46:24

标签: c# asp.net roles createuserwizard

我想在使用ASP.Net用户创建向导创建角色时为用户分配角色。

我按照以下答案中的步骤进行了操作:

Adding roles to the 'CreateUserWizard'

ASP.net failing to add role to user

但我总是收到一条错误消息(参数'username'不能为空。 参数名称:用户名)和红色的颜色如下:

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

有什么问题?

这是我背后的代码:

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);
}

}

提前致谢。

0 个答案:

没有答案
相关问题