MembershipCreateUserException Constructors

Definition

Initializes a new instance of the MembershipCreateUserException class.

Overloads

MembershipCreateUserException()

Initializes a new instance of the MembershipCreateUserException class.

MembershipCreateUserException(String)

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

MembershipCreateUserException(MembershipCreateStatus)

Initializes a new instance of the MembershipCreateUserException class with the specified StatusCode value.

MembershipCreateUserException(SerializationInfo, StreamingContext)

Initializes a new instance of the MembershipCreateUserException class with the supplied serialization information and context.

MembershipCreateUserException(String, Exception)

Initializes a new instance of the MembershipCreateUserException class and sets the Message property to the supplied message and the InnerException property to the supplied innerException.

MembershipCreateUserException()

Initializes a new instance of the MembershipCreateUserException class.

public:
 MembershipCreateUserException();
public MembershipCreateUserException ();
Public Sub New ()

Examples

The following code example calls the Membership.CreateUser method to create a new membership user. If the user creation fails, a MembershipCreateUserException is thrown.

public MembershipUser MyCreateUser(string username, string password, string email,
                                   string question, string answer)
{
  MembershipCreateStatus status;

  MembershipUser u = Membership.CreateUser(username, password, email, question, 
                                           answer, true, out status);
  if (u == null)
  {
    throw new MembershipCreateUserException();
  }

  return u;
}
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()
  End If

  Return u
End Function

Remarks

An instance of the MembershipCreateUserException class is thrown by the Membership.CreateUser method when the user is not created.

See also

Applies to

MembershipCreateUserException(String)

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

public:
 MembershipCreateUserException(System::String ^ message);
public MembershipCreateUserException (string message);
new System.Web.Security.MembershipCreateUserException : string -> System.Web.Security.MembershipCreateUserException
Public Sub New (message As String)

Parameters

message
String

A description of the reason for the exception.

Examples

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 MembershipUser MyCreateUser(string username, string password, string email,
                                   string question, string answer)
{
  MembershipCreateStatus status;

  MembershipUser u = Membership.CreateUser(username, password, email, question, 
                                           answer, true, out status);
  if (u == null)
  {
    throw new MembershipCreateUserException(GetErrorMessage(status));
  }

  return u;
}

public string GetErrorMessage(MembershipCreateStatus status)
{
   switch (status)
   {
      case MembershipCreateStatus.DuplicateUserName:
        return "Username already exists. Please enter a different user name.";

      case MembershipCreateStatus.DuplicateEmail:
        return "A username for that email address already exists. Please enter a different email address.";

      case MembershipCreateStatus.InvalidPassword:
        return "The password provided is invalid. Please enter a valid password value.";

      case MembershipCreateStatus.InvalidEmail:
        return "The email 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.";

      default:
        return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
   }
}
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 email address already exists. Please enter a different email address."

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

      Case MembershipCreateStatus.InvalidEmail
        Return "The email 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

Remarks

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.

See also

Applies to

MembershipCreateUserException(MembershipCreateStatus)

Initializes a new instance of the MembershipCreateUserException class with the specified StatusCode value.

public:
 MembershipCreateUserException(System::Web::Security::MembershipCreateStatus statusCode);
public MembershipCreateUserException (System.Web.Security.MembershipCreateStatus statusCode);
new System.Web.Security.MembershipCreateUserException : System.Web.Security.MembershipCreateStatus -> System.Web.Security.MembershipCreateUserException
Public Sub New (statusCode As MembershipCreateStatus)

Parameters

statusCode
MembershipCreateStatus

A MembershipCreateStatus enumeration value that describes the reason for the exception.

Examples

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

public MembershipUser MyCreateUser(string username, string password, string email,
                                   string question, string answer)
{
  MembershipCreateStatus status;

  MembershipUser u = Membership.CreateUser(username, password, email, question, 
                                           answer, true, out status);

  if (u == null)
  {
    throw new MembershipCreateUserException(status);
  }

  return u;
}
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(status)
  End If

  Return u
End Function

Remarks

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

The statusCode parameter enables you to indicate why the MembershipCreateUserException was thrown. The statusCode parameter value is exposed by the StatusCode property.

See also

Applies to

MembershipCreateUserException(SerializationInfo, StreamingContext)

Initializes a new instance of the MembershipCreateUserException class with the supplied serialization information and context.

protected:
 MembershipCreateUserException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected MembershipCreateUserException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Web.Security.MembershipCreateUserException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Web.Security.MembershipCreateUserException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parameters

info
SerializationInfo

The SerializationInfo that holds the serialized object data about the exception being thrown.

context
StreamingContext

The StreamingContext that contains contextual information about the source or destination.

Examples

The following code example shows an implementation of the MembershipCreateUserException class that calls the protected constructor of the base class with the supplied serialization information and context.

using System.Web.Security;
using System.Runtime.Serialization;

public sealed class MyCreateUserException : MembershipCreateUserException
{
  public MyCreateUserException(SerializationInfo info, StreamingContext context) : base(info, context)
  {
  }
}
Imports System.Web.Security
Imports System.Runtime.Serialization

Public NotInheritable Class MyCreateUserException
  Inherits MembershipCreateUserException

  Public Sub New (info As SerializationInfo, context As StreamingContext)
    MyBase.New(info, context)
  End Sub
End Class

Remarks

This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see XML and SOAP Serialization.

See also

Applies to

MembershipCreateUserException(String, Exception)

Initializes a new instance of the MembershipCreateUserException class and sets the Message property to the supplied message and the InnerException property to the supplied innerException.

public:
 MembershipCreateUserException(System::String ^ message, Exception ^ innerException);
public MembershipCreateUserException (string message, Exception innerException);
new System.Web.Security.MembershipCreateUserException : string * Exception -> System.Web.Security.MembershipCreateUserException
Public Sub New (message As String, innerException As Exception)

Parameters

message
String

A description of the reason for the exception.

innerException
Exception

The exception that caused the MembershipCreateUserException.

Examples

The following code example calls the CreateUser method to create a new membership user. If the user creation fails, a MembershipCreateUserException is thrown. If the exception is not a MembershipCreateUserException, the caught exception is supplied as the InnerException of the MembershipCreateUserException that is thrown.

public MembershipUser MyCreateUser(string username, string password, string email)
{
  MembershipUser u = null;

  try
  {
    u = Membership.CreateUser(username, password, email);
  }
  catch (MembershipCreateUserException e)
  {  
    throw e;
  }
  catch (Exception e)
  {  
    throw new MembershipCreateUserException("An exception occurred creating the user.", e);
  }

  return u;
}
Public Function MyCreateUser(username As String, password As String, email As String) As MembershipUser

  Dim u As MembershipUser = Nothing

  Try
    u = Membership.CreateUser(username, password, email)
  Catch e As MembershipCreateUserException
    Throw e
  Catch e As Exception  
    Throw New MembershipCreateUserException("An exception occurred creating the user.", e)
  End Try

  Return u
End Function

Remarks

An instance of the MembershipCreateUserException class is thrown by the Membership.CreateUser method when the user is not created.

You can use this overload of the MembershipCreateUserException constructor to supply information regarding a caught exception that occurred while the user was being created.

See also

Applies to