MembershipCreateUserException MembershipCreateUserException MembershipCreateUserException MembershipCreateUserException Class

Definition

Diese Ausnahme wird ausgelöst, wenn ein Benutzer nicht erfolgreich von einem Mitgliedschaftsanbieter erstellt wurde.The exception that is thrown when a user is not successfully created by a membership provider.

public ref class MembershipCreateUserException : Exception
[System.Serializable]
public class MembershipCreateUserException : Exception
type MembershipCreateUserException = class
    inherit Exception
Public Class MembershipCreateUserException
Inherits Exception
Vererbung
MembershipCreateUserExceptionMembershipCreateUserExceptionMembershipCreateUserExceptionMembershipCreateUserException
Attribute

Beispiele

Das folgende Codebeispiel erstellt einen neuen Benutzer für eine ASP.NET-Anwendung für die Verwendung der Formularauthentifizierung und ASP.NET-Mitgliedschaft konfiguriert.The following code example creates a new user for an ASP.NET application configured to use forms authentication and ASP.NET membership. Wenn der Benutzer nicht erfolgreich erstellt wurde, wird der Code fängt die MembershipCreateUserException und zeigt die angegebene Fehlermeldung an die StatusCode Eigenschaft.If the user is not created successfully, the code catches the MembershipCreateUserException and displays the message specified in the StatusCode property.

Wichtig

Dieses Beispiel enthält das Textfeld, das Benutzereingaben akzeptiert, die ein potenzielles Sicherheitsrisiko dar.This example contains a text box that accepts user input, which is a potential security threat. Standardmäßig stellen ASP.NET-Webseiten sicher, dass Benutzereingaben keine Skript- oder HTML-Elemente enthalten.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Weitere Informationen finden Sie unter Übersicht über Skriptangriffe.For more information, see Script Exploits Overview.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

public void CreateUser_OnClick(object sender, EventArgs args)
{
  MembershipCreateStatus result;

  try
  {
    // Create new user.

    if (Membership.RequiresQuestionAndAnswer)
    {
      MembershipUser newUser = Membership.CreateUser(
        UsernameTextbox.Text, 
        PasswordTextbox.Text, 
        EmailTextbox.Text,
        PasswordQuestionTextbox.Text,
        PasswordAnswerTextbox.Text,
        false,
        out result);
    }
    else 
    {
      MembershipUser newUser = Membership.CreateUser(
        UsernameTextbox.Text, 
        PasswordTextbox.Text, 
        EmailTextbox.Text);
    }

    Response.Redirect("login.aspx");
  }
  catch (MembershipCreateUserException e)
  {
    Msg.Text = GetErrorMessage(e.StatusCode);
  }
  catch (HttpException e)
  {
    Msg.Text = e.Message;
  }
}

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

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Create User</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Create New User</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Username:</td>
      <td><asp:Textbox id="UsernameTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
                                      ControlToValidate="UserNameTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /></td>
      <td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server"
                                      ControlToValidate="PasswordTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Confirm Password:</td>
      <td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td>
      <td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server"
                                      ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" />
          <asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server"
                                      ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
                                      Display="Static" ControlToCompare="PasswordTextBox"
                                      ErrorMessage="Confirm password must match password." />
      </td>
    </tr>
    <tr>
      <td>Email Address:</td>
      <td><asp:Textbox id="EmailTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                      ControlToValidate="EmailTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>


<% if (Membership.RequiresQuestionAndAnswer) { %>

    <tr>
      <td>Password Question:</td>
      <td><asp:Textbox id="PasswordQuestionTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="PasswordQuestionRequiredValidator" runat="server"
                                      ControlToValidate="PasswordQuestionTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Password Answer:</td>
      <td><asp:Textbox id="PasswordAnswerTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="PasswordAnswerRequiredValidator" runat="server"
                                      ControlToValidate="PasswordAnswerTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>

<% } %>


    <tr>
      <td></td>
      <td><asp:Button id="CreateUserButton" Text="Create User" OnClick="CreateUser_OnClick" runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Public Sub CreateUser_OnClick(sender As Object, args As EventArgs)
  Dim result As MembershipCreateStatus
  Try
    ' Create new user.

    Dim newUser As MembershipUser
    If Membership.RequiresQuestionAndAnswer Then
      newUser  = Membership.CreateUser( _
        UsernameTextbox.Text, _
        PasswordTextbox.Text, _
        EmailTextbox.Text, _
        PasswordQuestionTextbox.Text, _
        PasswordAnswerTextbox.Text, _
        false, _
        result)
    Else
      newUser  = Membership.CreateUser( _
        UsernameTextbox.Text, _
        PasswordTextbox.Text, _
        EmailTextbox.Text)
    End If

    Response.Redirect("login.aspx")

  Catch e As MembershipCreateUserException
    Msg.Text = GetErrorMessage(e.StatusCode)
  Catch e As HttpException
    Msg.Text = e.Message
  End Try
End Sub

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

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Create User</title>
</head>
<body>

<form id="form1" runat="server">
  <h3>Create New User</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <table cellpadding="3" border="0">
    <tr>
      <td>Username:</td>
      <td><asp:Textbox id="UsernameTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
                                      ControlToValidate="UserNameTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /></td>
      <td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server"
                                      ControlToValidate="PasswordTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Confirm Password:</td>
      <td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td>
      <td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server"
                                      ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" />
          <asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server"
                                      ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
                                      Display="Static" ControlToCompare="PasswordTextBox"
                                      ErrorMessage="Confirm password must match password." />
      </td>
    </tr>
    <tr>
      <td>Email Address:</td>
      <td><asp:Textbox id="EmailTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
                                      ControlToValidate="EmailTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>


<% If Membership.RequiresQuestionAndAnswer Then %>

    <tr>
      <td>Password Question:</td>
      <td><asp:Textbox id="PasswordQuestionTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="PasswordQuestionRequiredValidator" runat="server"
                                      ControlToValidate="PasswordQuestionTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>
    <tr>
      <td>Password Answer:</td>
      <td><asp:Textbox id="PasswordAnswerTextbox" runat="server" /></td>
      <td><asp:RequiredFieldValidator id="PasswordAnswerRequiredValidator" runat="server"
                                      ControlToValidate="PasswordAnswerTextbox" ForeColor="red"
                                      Display="Static" ErrorMessage="Required" /></td>
    </tr>

<% End If %>


    <tr>
      <td></td>
      <td><asp:Button id="CreateUserButton" Text="Create User" OnClick="CreateUser_OnClick" runat="server" /></td>
    </tr>
  </table>
</form>

</body>
</html>

Hinweise

Eine Instanz von der MembershipCreateUserException Klasse ausgelöst, wenn eine CreateUser -Vorgang fehl.An instance of the MembershipCreateUserException class is thrown when a CreateUser operation fails.

Hinweis

Wenn Sie nicht mit den Mitgliedschaftsfunktionen von ASP.NET vertraut sind, finden Sie unter Einführung in die Mitgliedschaft vor dem fortfahren.If you are not familiar with the membership features of ASP.NET, see Introduction to Membership before continuing. Eine Liste weiterer Themen zur Mitgliedschaft, finden Sie unter Verwalten von Benutzern durch Mitgliedschaft.For a list of other topics related to membership, see Managing Users by Using Membership.

Die StatusCode Eigenschaft gibt den Grund für die Ausnahme aus, damit Sie diese angemessen behandeln können.The StatusCode property indicates the reason for the exception so you can handle it appropriately.

Konstruktoren

MembershipCreateUserException() MembershipCreateUserException() MembershipCreateUserException() MembershipCreateUserException()

Initialisiert eine neue Instanz der MembershipCreateUserException-Klasse.Initializes a new instance of the MembershipCreateUserException class.

MembershipCreateUserException(MembershipCreateStatus) MembershipCreateUserException(MembershipCreateStatus) MembershipCreateUserException(MembershipCreateStatus) MembershipCreateUserException(MembershipCreateStatus)

Initialisiert eine neue Instanz der MembershipCreateUserException-Klasse mit dem angegebenen StatusCode-Wert.Initializes a new instance of the MembershipCreateUserException class with the specified StatusCode value.

MembershipCreateUserException(SerializationInfo, StreamingContext) MembershipCreateUserException(SerializationInfo, StreamingContext) MembershipCreateUserException(SerializationInfo, StreamingContext) MembershipCreateUserException(SerializationInfo, StreamingContext)

Initialisiert eine neue Instanz der MembershipCreateUserException-Klasse mit den angegebenen Serialisierungsinformationen und dem angegebenen Kontext.Initializes a new instance of the MembershipCreateUserException class with the supplied serialization information and context.

MembershipCreateUserException(String) MembershipCreateUserException(String) MembershipCreateUserException(String) MembershipCreateUserException(String)

Initialisiert eine neue Instanz der MembershipCreateUserException-Klasse und legt die Message-Eigenschaft auf den bereitgestellten message-Parameterwert fest.Initializes a new instance of the MembershipCreateUserException class and sets the Message property to the supplied message parameter value

MembershipCreateUserException(String, Exception) MembershipCreateUserException(String, Exception) MembershipCreateUserException(String, Exception) MembershipCreateUserException(String, Exception)

Initialisiert eine neue Instanz der MembershipCreateUserException-Klasse und legt die Message-Eigenschaft auf die angegebene message und die InnerException-Eigenschaft auf die angegebene innerException fest.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.

Eigenschaften

Data Data Data Data

Ruft eine Auflistung von Schlüssel-Wert-Paaren ab, die zusätzliche benutzerdefinierte Informationen über die Ausnahme bereitstellen.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

Ruft einen Link zur Hilfedatei ab, die dieser Ausnahme zugeordnet ist, oder legt einen Link fest.Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

Ruft HRESULT ab oder legt HRESULT fest. Dies ist ein codierter Wert, der einer bestimmten Ausnahme zugeordnet ist.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

Ruft die Exception-Instanz ab, die die aktuelle Ausnahme verursacht hat.Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

Ruft eine Meldung ab, die die aktuelle Ausnahme beschreibt.Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

Gibt den Namen der Anwendung oder des Objekts zurück, die bzw. das den Fehler verursacht hat, oder legt diesen fest.Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

Ruft eine Zeichenfolgendarstellung der unmittelbaren Frames in der Aufrufliste ab.Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
StatusCode StatusCode StatusCode StatusCode

Ruft eine Beschreibung des Grundes für die Ausnahme ab.Gets a description of the reason for the exception.

TargetSite TargetSite TargetSite TargetSite

Ruft die Methode ab, die die aktuelle Ausnahme auslöst.Gets the method that throws the current exception.

(Inherited from Exception)

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

Gibt beim Überschreiben in einer abgeleiteten Klasse eine Exception zurück, die die ursprüngliche Ursache für eine oder mehrere nachfolgende Ausnahmen ist.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Füllt eine SerializationInfo mit den Daten auf, die zum Serialisieren des Zielobjekts erforderlich sind.Populates a SerializationInfo with the data needed to serialize the target object.

GetType() GetType() GetType() GetType()

Ruft den Laufzeittyp der aktuellen Instanz ab.Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Erstellt eine Zeichenfolgendarstellung der aktuellen Ausnahme und gibt diese zurück.Creates and returns a string representation of the current exception.

(Inherited from Exception)

Ereignisse

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

Tritt auf, wenn eine Ausnahme serialisiert wird, um ein Ausnahmezustandsobjekt mit serialisierten Daten über die Ausnahme zu erstellen.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Gilt für:

Siehe auch