共用方式為


MembershipCreateUserException 建構函式

定義

初始化 MembershipCreateUserException 類別的新執行個體。

多載

MembershipCreateUserException()

初始化 MembershipCreateUserException 類別的新執行個體。

MembershipCreateUserException(String)

初始化 MembershipCreateUserException 類別的新執行個體,並將 Message 屬性設為所提供的 message 參數值。

MembershipCreateUserException(MembershipCreateStatus)

使用指定的 StatusCode 值,初始化 MembershipCreateUserException 類別的新執行個體。

MembershipCreateUserException(SerializationInfo, StreamingContext)

使用提供的序列化資訊和內容,初始化 MembershipCreateUserException 類別的新執行個體。

MembershipCreateUserException(String, Exception)

MembershipCreateUserException 類別的新執行個體初始化,並將 Message 屬性設為提供的 message,而將 InnerException 屬性設為提供的 innerException

MembershipCreateUserException()

初始化 MembershipCreateUserException 類別的新執行個體。

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

範例

下列程式代碼範例會 Membership.CreateUser 呼叫 方法來建立新的成員資格使用者。 如果使用者建立失敗, MembershipCreateUserException 則會擲回 。

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

備註

未建立使用者時,方法會擲回 Membership.CreateUser 類別的MembershipCreateUserException實例。

另請參閱

適用於

MembershipCreateUserException(String)

初始化 MembershipCreateUserException 類別的新執行個體,並將 Message 屬性設為所提供的 message 參數值。

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)

參數

message
String

例外狀況的原因說明。

範例

下列程式代碼範例會 Membership.CreateUser 呼叫 方法來建立新的成員資格使用者。 如果使用者建立失敗, MembershipCreateUserException 則會根據 StatusCode 方法所 CreateUser 傳回的 ,擲回訊息。

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

備註

未建立使用者時,Membership.CreateUser方法MembershipCreateUserException會擲回 類別。

您可以使用 message 參數,將例外狀況的 屬性設定 Message 為例外狀況原因的有意義描述。

另請參閱

適用於

MembershipCreateUserException(MembershipCreateStatus)

使用指定的 StatusCode 值,初始化 MembershipCreateUserException 類別的新執行個體。

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)

參數

statusCode
MembershipCreateStatus

MembershipCreateStatus 列舉值,描述例外狀況的原因。

範例

下列程式代碼範例會 CreateUser 呼叫 方法來建立新的成員資格使用者。 如果使用者建立失敗, MembershipCreateUserException 則會擲回 方法 StatusCode 所傳回的 CreateUser

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

備註

未建立使用者時,Membership.CreateUser方法MembershipCreateUserException會擲回 類別。

參數 statusCode 可讓您指出擲回 的原因 MembershipCreateUserException 。 參數 statusCode 值是由 StatusCode 屬性公開。

另請參閱

適用於

MembershipCreateUserException(SerializationInfo, StreamingContext)

使用提供的序列化資訊和內容,初始化 MembershipCreateUserException 類別的新執行個體。

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)

參數

info
SerializationInfo

SerializationInfo,包含所擲回之例外狀況的相關序列化物件資料。

context
StreamingContext

包含有關來源或目的端內容資訊的 StreamingContext

範例

下列程式代碼範例示範 類別的 MembershipCreateUserException 實作,這個實作會使用提供的串行化資訊和內容來呼叫基類的受保護建構函式。

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

備註

這個建構函式是在還原序列化期間呼叫,以便重新組成透過資料流傳輸的例外狀況物件。 如需詳細資訊,請參閱 < XML 和 SOAP 序列化

另請參閱

適用於

MembershipCreateUserException(String, Exception)

MembershipCreateUserException 類別的新執行個體初始化,並將 Message 屬性設為提供的 message,而將 InnerException 屬性設為提供的 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)

參數

message
String

例外狀況的原因說明。

innerException
Exception

導致 MembershipCreateUserException 的例外狀況。

範例

下列程式代碼範例會 CreateUser 呼叫 方法來建立新的成員資格使用者。 如果使用者建立失敗, MembershipCreateUserException 則會擲回 。 如果例外狀況不是 MembershipCreateUserException,則會將攔截到的例外狀況當做 InnerException 擲回的 MembershipCreateUserException 提供。

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

備註

未建立使用者時,方法會擲回 Membership.CreateUser 類別的MembershipCreateUserException實例。

您可以使用這個建構函式的多 MembershipCreateUserException 載,提供使用者建立時所發生攔截例外狀況的相關信息。

另請參閱

適用於