1

如何在 期间将用户添加到角色CreateUserWizard.CreatedUser

这段代码有什么问题:

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles CreateUserWizard1.CreatedUser
    Dim username As TextBox = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")
    Dim literal1 As Literal = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Literal1")
    Dim sql As SqlDataSource = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SqlDataSource1")
    Dim user As MembershipUser = Membership.GetUser(username.Text)
    Dim pwd As TextBox = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password")
    Dim obj As Object
    obj = user.ProviderUserKey
    sql.InsertParameters.Add("UserId", obj.ToString)
    Roles.AddUserToRole(CreateUserWizard1.UserName, literal1.Text.ToString)
    sql.Insert()
End Sub

错误:

参数“用户名”不能为空。参数名称:用户名。

4

1 回答 1

0

我不熟悉您使用的向导,您是否在调暗用户的那一行收到错误?还是以后的roles.addUserToRole?

如果您仅在角色.addUserToRole 上获取它,为什么不将 CreateWizard1.UserName 更改为 username.text,就像您在调暗用户时使用的那样?

于 2011-04-18T13:23:58.970 回答