2011-01-22 106 views
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.

+0

您是否安裝了任何/默認的會員供應商?您是否使用內置的成員/角色基礎架構/數據庫? – abatishchev 2011-01-22 18:21:17

回答

0

我不熟悉您正在使用的嚮導,你才能上線,你朦朧的用戶錯誤?或稍後在roles.addUserToRole?

如果您只是在roles.addUserToRole上獲取它,爲什麼不將CreateWizard1.UserName更改爲username.text,因爲您在變暗用戶時使用了該方法?