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.

C#
public MembershipCreateUserException();

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.

C#
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;
}

Remarks

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

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

MembershipCreateUserException(String)

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

C#
public MembershipCreateUserException(string message);

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.

C#
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.";
   }
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

MembershipCreateUserException(MembershipCreateStatus)

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

C#
public MembershipCreateUserException(System.Web.Security.MembershipCreateStatus statusCode);

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.

C#
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;
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

MembershipCreateUserException(SerializationInfo, StreamingContext)

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

C#
protected MembershipCreateUserException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);

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.

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

public sealed class MyCreateUserException : MembershipCreateUserException
{
  public MyCreateUserException(SerializationInfo info, StreamingContext context) : base(info, context)
  {
  }
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

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.

C#
public MembershipCreateUserException(string message, Exception innerException);

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.

C#
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;
}

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1