MembershipCreateUserException Constructor (String)

 

Initializes a new instance of the MembershipCreateUserException class and sets the Message property to the supplied message parameter value

Namespace:   System.Web.Security
Assembly:  System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)

Public Sub New (
	message As String
)

Parameters

message
Type: System.String

A description of the reason for the exception.

The MembershipCreateUserException class is thrown by the Membership.CreateUser method when the user is not created.

You can use the message parameter to set the Message property of the exception to a meaningful description of the reason for the exception.

The following code example calls the Membership.CreateUser method to create a new membership user. If the user creation fails, a MembershipCreateUserException is thrown with a message based on the StatusCode returned by the CreateUser method.

Public Function MyCreateUser(username As String, password As String, email As String, _
                             question As String, answer As String) As MembershipUser

  Dim status As MembershipCreateStatus

  Dim u As MembershipUser = Membership.CreateUser(username, password, email, question, _
                                                  answer, True, status)
  If u Is Nothing Then
    Throw New MembershipCreateUserException(GetErrorMessage(status))
  End If

  Return u
End Function


Public Function GetErrorMessage(status As MembershipCreateStatus) As String

   Select Case status
      Case MembershipCreateStatus.DuplicateUserName
        Return "Username already exists. Please enter a different user name."

      Case MembershipCreateStatus.DuplicateEmail
        Return "A username for that e-mail address already exists. Please enter a different e-mail address."

      Case MembershipCreateStatus.InvalidPassword
        Return "The password provided is invalid. Please enter a valid password value."

      Case MembershipCreateStatus.InvalidEmail
        Return "The e-mail address provided is invalid. Please check the value and try again."

      Case MembershipCreateStatus.InvalidAnswer
        Return "The password retrieval answer provided is invalid. Please check the value and try again."

      Case MembershipCreateStatus.InvalidQuestion
        Return "The password retrieval question provided is invalid. Please check the value and try again."

      Case MembershipCreateStatus.InvalidUserName
        Return "The user name provided is invalid. Please check the value and try again."

      Case MembershipCreateStatus.ProviderError
        Return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."

      Case MembershipCreateStatus.UserRejected
        Return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."

      Case Else
        Return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."
   End Select
End Function

.NET Framework
Available since 2.0
Return to top
Show: