1
如何在CreateUserWizard.CreatedUser
期間向用戶添加角色?如何在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
錯誤:
The parameter 'username' must not be empty. Parameter name: username.
您是否安裝了任何/默認的會員供應商?您是否使用內置的成員/角色基礎架構/數據庫? – abatishchev 2011-01-22 18:21:17