如何在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
错误:
参数'username'不能为空。参数名称:用户名。
答案 0 :(得分:0)
我不熟悉你正在使用的向导,你是否在你昏暗的用户线上得到了错误?或者稍后在roles.addUserToRole上?
如果您只是在roles.addUserToRole上获取它,为什么不将CreateWizard1.UserName更改为username.text,就像您在调暗用户时使用的那样?