How to add user to roles during CreateUserWizard.CreatedUser step
How to add user to roles during CreateUserWizard.CreatedUser
?
What's wrong in this code:
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
Error:
The parameter 'username' must not be empty. Parameter name: username.
I am not familiar with the wizard you are using, are you getting the error on the line where you dim user? or later on the roles.addUserToRole?
If you are only getting it on the roles.addUserToRole, why not change CreateWizard1.UserName to username.text as you used when you dimmed user?
精彩评论