OK For those of you who want to add additional info to the create user wizard, the easiest way is to use the membership system but create your own form.
Since I had so much trouble doing it I will post the code here and you can copy it for yourself.
Setup: I have 3 sections
1. The CreateUser section which is utilized by aspnet_Membership - Utilizes the aspnet_Users table and aspnet_Membership table - The textbox names that the wizard uses I used.
2. Personal Information - Information about the new User - Utilizes a table named customers_personal
3. Notify Section - Emails and Text messages me, and sends a confirmation email to the new user.
I also add the new user to a role.
Protected Sub CreateUserButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CreateUserButton.Click
'Create A New User in aspnet_Membership
Dim createStatus As MembershipCreateStatus
Dim newUser As MembershipUser = Membership.CreateUser(UserName.Text, Password.Text, Email.Text, Question.Text, Answer.Text, True, createStatus)
'Error Checking
Select Case createStatus
Case MembershipCreateStatus.Success
AddExtraInfo()
AddUserToRole()
Notify()
Response.Redirect("AccountCreated.aspx")
Case MembershipCreateStatus.InvalidUserName
ErrorMessage.Text = "That is an Invalid User Name."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.InvalidPassword
ErrorMessage.Text = "The Password You Entered is Not Valid. Password Must be a Minimum of 7 Characters with 1 non-Alphanumeric Character."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.InvalidQuestion
ErrorMessage.Text = "That is not a valid Question."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.InvalidAnswer
ErrorMessage.Text = "That is not a valid Answer."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.InvalidEmail
ErrorMessage.Text = "That is not a valid Email Address."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.DuplicateUserName
ErrorMessage.Text = "User Name Already Exists, Please Select Another User Name"
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.DuplicateEmail
ErrorMessage.Text = "A User with That Email Address Already Exists."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.UserRejected
ErrorMessage.Text = "We are sorry but we cannot create your account at this time."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Check Error Message"
Case MembershipCreateStatus.InvalidProviderUserKey
ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Try Again"
Case MembershipCreateStatus.DuplicateProviderUserKey
ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Try Again"
Case MembershipCreateStatus.ProviderError
ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Try Again"
Case Else
ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
SucessLabel.Text = "Your New Account has not been created!"
ThankYouLabel.Text = "Please Try Again"
End Select
End Sub
Private Sub AddUserToRole()
'Add the new user to a role - optional
Roles.AddUserToRole(UserName.Text, "[role name]")
End Sub
Private Sub AddExtraInfo()
'Declare the customerType
Dim customerType As String = "Personal"
'Get the UserID
Dim newUser As MembershipUser = Membership.GetUser(UserName.Text)
Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)
'Open the connection
Dim DataSource As String = ConfigurationManager.ConnectionStrings("[InsertYourConnectionStringHere]").ConnectionString
Using myConnection As New SqlConnection(DataSource)
myConnection.Open()
'Add userID to Customer_id table to create a numeric CustomerID - Stored Procedure then retrieve that new CustomerID to put into the customers info table
Dim selectSQL As New SqlCommand("RetrieveCustomerId", myConnection)
selectSQL.CommandType = Data.CommandType.StoredProcedure
selectSQL.Parameters.AddWithValue("@UserId", newUserId)
Dim NewCustomerID As Integer = (selectSQL.ExecuteScalar())
'Insert Additional Info into customers_personal Table
Dim insertSql As String = "INSERT INTO customers.personal (CustomerID, FirstName, LastName, SpouseName, Phone, CellPhone, Address, Apt, City, State, ZipCode, CustomerSince, BirthDate, Anniversary, Email) VALUES (@CustomerID, @FirstName, @LastName, @SpouseName, @Phone, @CellPhone, @Address, @Apt, @City, @State, @ZipCode, GetDate(), @BirthDate, @Anniversary, @Email)"
Dim myOtherCommand As New SqlCommand(insertSql, myConnection)
myOtherCommand.Parameters.AddWithValue("@CustomerID", NewCustomerID)
myOtherCommand.Parameters.AddWithValue("@FirstName", txtFirstName.Text)
myOtherCommand.Parameters.AddWithValue("@LastName", txtLastName.Text)
myOtherCommand.Parameters.AddWithValue("@SpouseName", txtSpouse.Text)
myOtherCommand.Parameters.AddWithValue("@Phone", txtPhone.Text)
myOtherCommand.Parameters.AddWithValue("@CellPhone", txtCellPhone.Text)
myOtherCommand.Parameters.AddWithValue("@Address", txtAddress.Text)
myOtherCommand.Parameters.AddWithValue("@Apt", txtSuite.Text)
myOtherCommand.Parameters.AddWithValue("@City", txtCity.Text)
myOtherCommand.Parameters.AddWithValue("@State", txtState.Text)
myOtherCommand.Parameters.AddWithValue("@ZipCode", txtZipCode.Text)
myOtherCommand.Parameters.AddWithValue("@Email", txtEmail.Text)
myOtherCommand.Parameters.AddWithValue("@BirthDate", BirthMonth.SelectedValue)
myOtherCommand.Parameters.AddWithValue("@Anniversary", Anniversary.SelectedValue)
myOtherCommand.ExecuteNonQuery()
myConnection.Close()
End Using
End Sub
Private Sub Notify()
'Send Me a Text Message
Dim notification As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
notification.From = New System.Net.Mail.MailAddress("address@mycleaningsolution.com")
notification.To.Add(New System.Net.Mail.MailAddress("mobilephone#@messaging.sprintpcs.com"))
notification.Priority = Net.Mail.MailPriority.High
notification.Subject = "New User"
notification.Body = " A New Business User Has Created An Account"
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClient.Send(notification)
'Send Me an Email
Dim contact As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
contact.From = New System.Net.Mail.MailAddress("address@mycleaningsolution.com")
contact.To.Add(New System.Net.Mail.MailAddress("address@mycleaningsolution.com"))
contact.Priority = Net.Mail.MailPriority.High
contact.Subject = "New User"
contact.Body = " A New Business User Has Created An Account"
Dim smtpClient2 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClient2.Send(contact)
'Send Acknowledgement Email to Customer
Dim verify As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
verify.From = New System.Net.Mail.MailAddress("newuser@mycleaningsolution.com")
verify.To.Add(New System.Net.Mail.MailAddress(Email.Text))
verify.Priority = Net.Mail.MailPriority.Normal
verify.Subject = "New User Account Created"
verify.Body = " Your New User Account has been created for " + UserName.Text + " at http://www.MyCleaningSolution.com"
Dim smtpClient3 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClient3.Send(verify)
End Sub
This is the Stored Procedure to retrieve the CustomerID
ALTER PROCEDURE RetrieveCustomerID
(
@UserId uniqueidentifier
)
AS
INSERT INTO customer_id (UserId)
VALUES (@UserId)
SELECT SCOPE_IDENTITY()
It inserts the New UserId into the table which has a primary key of CustomerID as an int Identity that increments by 1 everytime. If you have only one table for collecting customer information, you can skip this step. I have separate tables for company and personal clients and need to make sure I do not get two sets of CustomerID's (basically a Customer#)
Obviously, the customerID table, the AddUsertoRole, and the email notification are all optional
"Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"
Robert Hall
CEO and Founder
My Service Solutions, Inc.