Hi,
I have created a new step in the CreateUserWizard control. The purpose of this step is to collect some information from the user, like his first name, last name, and most importantly his role. On clicking the Finish button for this step, I want to save the role in Roles and the other information in the user's profile. I have written the following code on the click event:
Protected Sub CreateUserWizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles CreateUserWizard1.FinishButtonClick
Roles.AddUserToRole(User.Identity.Name, UserTypes.SelectedItem.Value)
Dim userProfile As ProfileCommon = CType(ProfileCommon.Create(CreateUserWizard1.UserName, True), ProfileCommon)
With userProfile.UserInfo
.UserTitle = UserTitle.SelectedItem.Value
.FirstName = txtFName.Text
.MiddleName = txtMName.Text
.LastName = txtLName.Text
.Role = txtRole.Text
.Company = txtCompany.Text
End With
userProfile.Save()
End Sub
But, I receive the following error when this gets executed:
The role '' was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.Provider.ProviderException: The role '' was not found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[ProviderException: The role '' was not found.]
System.Web.Security.SqlRoleProvider.AddUsersToRolesCore(SqlConnection conn, String usernames, String roleNames) +2189583
System.Web.Security.SqlRoleProvider.AddUsersToRoles(String[] usernames, String[] roleNames) +705
System.Web.Security.Roles.AddUserToRole(String username, String roleName) +341
registerUser.CreateUserWizard1_FinishButtonClick(Object sender, WizardNavigationEventArgs e) +146
System.Web.UI.WebControls.Wizard.OnFinishButtonClick(WizardNavigationEventArgs e) +105
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +693
System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +149
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
|
The problem lies in the line;
Roles.AddUserToRole(User.Identity.Name, UserTypes.SelectedItem.Value)
When I comment this line, everything works perfectly. Can anyone help me out with this? How can I have the roles also saved to the database?