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 MembershipCreateUserException(
	string message
)

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 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 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.";

      default:
        return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
   }
}

.NET Framework
Available since 2.0
Return to top
Show: