MembershipCreateStatus 列挙体とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MembershipCreateStatus 列挙体の意味・解説 

MembershipCreateStatus 列挙体

メモ : この列挙体は、.NET Framework version 2.0 で新しく追加されたものです。

CreateUser 操作の結果を示します。

名前空間: System.Web.Security
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Enumeration MembershipCreateStatus
Dim instance As MembershipCreateStatus
public enum MembershipCreateStatus
public enum class MembershipCreateStatus
public enum MembershipCreateStatus
public enum MembershipCreateStatus
メンバメンバ
 メンバ名説明
DuplicateEmailこのアプリケーションのデータベースに、指定した電子メール アドレスが既に存在しています。 
DuplicateProviderUserKeyこのアプリケーションのデータベースに、指定したプロバイダ ユーザー キーが既に存在しています。 
DuplicateUserNameこのアプリケーションのデータベースに、指定したユーザー名が既に存在しています。 
InvalidAnswerパスワードの解答の形式が正しくありません。 
InvalidEmail電子メール アドレスの形式が正しくありません。 
InvalidPasswordパスワードの形式が正しくありません。 
InvalidProviderUserKeyプロバイダ ユーザー キーの型または形式が無効です。 
InvalidQuestionパスワードの質問の形式が正しくありません。 
InvalidUserNameデータベースにユーザー名が見つかりませんでした。 
ProviderError他の MembershipCreateStatus 列挙値によって示されないエラーをプロバイダが返しました。 
Successユーザーの作成に成功しました。 
UserRejectedプロバイダによって定義されている理由によりユーザーが作成されませんでした。 
解説解説

MembershipCreateStatus 列挙型は、新しいユーザーの作成が成功したか失敗したかを示します。CreateUser 操作に失敗した場合、MembershipCreateStatus 列挙型はその失敗の原因を示します。

MembershipCreateStatus 型の出力パラメータを指定しない CreateUser メソッド オーバーロードを使用した場合に、新しいユーザーの作成に失敗すると、StatusCode プロパティが MembershipCreateStatus 列挙値の 1 つに設定された MembershipCreateUserException がスローされます。

使用例使用例

フォーム認証と ASP.NET メンバシップを使用するように構成された ASP.NET アプリケーションの新しいユーザーを作成するコード例を次に示します。ユーザーの作成に失敗した場合、そのユーザーに対してメッセージが表示されます。ユーザーの作成に成功した場合、ユーザーはアプリケーションのログイン ページにリダイレクトされます。このコード例では、MembershipCreateStatus 列挙型を使用して、エラー時にユーザーに表示されるメッセージが決定されます。

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security"
 %>
<script runat="server">

Public Sub CreateUser_OnClick(sender As
 Object, args As EventArgs)

  ' Create new user and retrieve create status result.

  Dim status As MembershipCreateStatus
  Dim passwordQuestion As String
 = ""
  Dim passwordAnswer As String
 = ""

  If Membership.RequiresQuestionAndAnswer Then
    passwordQuestion = PasswordQuestionTextbox.Text
    passwordAnswer = PasswordAnswerTextbox.Text
  End If

  Try
    Dim newUser As MembershipUser = Membership.CreateUser(UsernameTextbox.Text,
 PasswordTextbox.Text, _
                                                   EmailTextbox.Text, passwordQuestion
,
 _
                                                   passwordAnswer, True,
 status)
    If newUser Is Nothing
 Then
      Msg.Text = GetErrorMessage(status)
    Else
       Response.Redirect("login.aspx")
    End If
  Catch
    Msg.Text = "An exception occurred creating the user."
  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 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."

      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>
<head>
<title>Create User</title>
</head>
<body>

<form runat="server">
  <h3>Create New User</h3>
  <asp:Label id="Msg" ForeColor="maroon"
 runat="server" />
  <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>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">

public void CreateUser_OnClick(object sender,
 EventArgs args)
{
  // Create new user and retrieve create status result.

  MembershipCreateStatus status;
  string passwordQuestion = "";
  string passwordAnswer = "";

  if (Membership.RequiresQuestionAndAnswer)
  {
    passwordQuestion = PasswordQuestionTextbox.Text;
    passwordAnswer = PasswordAnswerTextbox.Text;
  }

  try
  {
    MembershipUser newUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text,
 
                                                   EmailTextbox.Text, passwordQuestion
,
                                                   passwordAnswer, true,
 out status);
    if (newUser == null)
    {
      Msg.Text = GetErrorMessage(status);
    }
    else
    {
      Response.Redirect("login.aspx");
    }
  }
  catch
  {
    Msg.Text = "An exception occurred creating the user.";
  }
}

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

</script>

<html>
<head>
<title>Create User</title>
</head>
<body>

<form 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

MembershipCreateStatus 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MembershipCreateStatus 列挙体のページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS