Membership.CreateUser Membership.CreateUser Membership.CreateUser Membership.CreateUser Method

定義

新しいユーザーをデータ ストアに追加します。Adds a new user to the data store.

オーバーロード

CreateUser(String, String) CreateUser(String, String) CreateUser(String, String) CreateUser(String, String)

新しいユーザーをデータ ストアに追加します。Adds a new user to the data store.

CreateUser(String, String, String) CreateUser(String, String, String) CreateUser(String, String, String) CreateUser(String, String, String)

電子メール アドレスを指定して新しいユーザーをデータ ストアに追加します。Adds a new user with a specified email address to the data store.

CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus)

プロパティ値を指定して新しいユーザーをデータ ストアに追加し、ユーザーの作成に成功したかどうか、または失敗の理由を示すステータス パラメーターを返します。Adds a new user with specified property values to the data store and returns a status parameter indicating that the user was successfully created or the reason the user creation failed.

CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

指定したプロパティ値と一意の ID で新しいユーザーをデータ ストアに追加し、ユーザーの作成に成功したかどうか、または失敗の理由を示すステータス パラメーターを返します。Adds a new user with specified property values and a unique identifier to the data store and returns a status parameter indicating that the user was successfully created or the reason the user creation failed.

CreateUser(String, String) CreateUser(String, String) CreateUser(String, String) CreateUser(String, String)

新しいユーザーをデータ ストアに追加します。Adds a new user to the data store.

public:
 static System::Web::Security::MembershipUser ^ CreateUser(System::String ^ username, System::String ^ password);
public static System.Web.Security.MembershipUser CreateUser (string username, string password);
static member CreateUser : string * string -> System.Web.Security.MembershipUser
Public Shared Function CreateUser (username As String, password As String) As MembershipUser

パラメーター

username
String String String String

新しいユーザーのユーザー名。The user name for the new user.

password
String String String String

新規ユーザーのパスワード。The password for the new user.

戻り値

新しく作成されたユーザーの MembershipUser オブジェクト。A MembershipUser object for the newly created user.

例外

ユーザーが作成されませんでした。The user was not created. StatusCode プロパティの MembershipCreateStatus 値を確認してください。Check the StatusCode property for a MembershipCreateStatus value.

次のコード例では、フォーム認証と ASP.NET のメンバーシップを使用するように構成の ASP.NET アプリケーションの新しいユーザーを作成します。The following code example creates a new user for an ASP.NET application configured to use forms authentication and ASP.NET membership. ユーザーが正常に作成されていない場合は、ユーザーにメッセージが表示されます。If the user is not created successfully, a message is displayed to the user. それ以外の場合、ユーザーは、アプリケーションのログイン ページにリダイレクトされます。Otherwise, the user is redirected to the login page for the application.

重要

この例には、潜在的なセキュリティ上の脅威がユーザー入力を受け付けるテキスト ボックスが含まれています。This example contains a text box that accepts user input, which is a potential security threat. 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 詳細については、「スクリプトによる攻略の概要」を参照してください。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)
{
  try
  {
    // Create new user.

    MembershipUser newUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text);


    // If user created successfully, set password question and answer (if applicable) and 
    // redirect to login page. Otherwise return an error message.

    if (Membership.RequiresQuestionAndAnswer)
    {
      newUser.ChangePasswordQuestionAndAnswer(PasswordTextbox.Text,
                                              PasswordQuestionTextbox.Text,
                                              PasswordAnswerTextbox.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>


<% 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)
  Try
    ' Create new user.

    Dim newUser As MembershipUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text)


    ' If user created successfully, set password question and answer (if applicable) and 
    ' redirect to login page. Otherwise Return an error message.

    If Membership.RequiresQuestionAndAnswer Then
    
      newUser.ChangePasswordQuestionAndAnswer(PasswordTextbox.Text, _
                                              PasswordQuestionTextbox.Text, _
                                              PasswordAnswerTextbox.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>


<% 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>

注釈

CreateUser データ ストアに新しいユーザーを追加し、返します、MembershipUser新しく作成したユーザーのオブジェクト。CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. ユーザーの作成に失敗した場合、MembershipCreateUserExceptionがスローされます。If the user creation fails, a MembershipCreateUserException is thrown. 取得することができます、MembershipCreateStatus値から、StatusCodeのプロパティ、MembershipCreateUserExceptionユーザーの作成が失敗した理由を示します。You can retrieve a MembershipCreateStatus value from the StatusCode property of the MembershipCreateUserException that indicates why user creation failed.

参照を使用してメンバーシップ ユーザーが作成された後、MembershipUserそのユーザーの設定を変更できますが、そのユーザーのオブジェクトで、MembershipUserパブリック メソッドなどChangePasswordQuestionAndAnswerアプリケーション、 RequiresQuestionAndAnswertrue、またはプロパティの値を設定して、MembershipUserオブジェクトとそれらに渡す、UpdateUserメソッド。Once a membership user has been created and you have a reference to a MembershipUser object for that user, you can modify the settings for that user with the MembershipUser public methods, such as ChangePasswordQuestionAndAnswer for applications where RequiresQuestionAndAnswer is true, or by setting the property values of the MembershipUser object and passing them to the UpdateUser method.

アプリケーションのデータ ソースで、ユーザーが既に存在する場合は取得できます、MembershipUserで既存のユーザーに対するオブジェクト、GetUserメソッド。If a user already exists in the data source for the application, you can obtain a MembershipUser object for the existing user with the GetUser method.

SqlMembershipProviderユーザーごとに一意の電子メール アドレスを要求するオプションを提供します。The SqlMembershipProvider provides an option to require a unique email address for each user. 場合、RequiresUniqueEmailプロパティはtrueのいずれかを使用する必要があります、CreateUserオーバー ロードを作成中のユーザーの電子メール アドレスを指定することができます。If the RequiresUniqueEmail property is true, you will need to use one of the CreateUser overloads that allows you to specify an email address for the user being created. それ以外の場合、MembershipCreateUserExceptionがスローされます。Otherwise, a MembershipCreateUserException will be thrown.

すべてのパラメーター値は、先頭と末尾のスペースが切り捨てられます。Leading and trailing spaces are trimmed from all parameter values.

こちらもご覧ください

CreateUser(String, String, String) CreateUser(String, String, String) CreateUser(String, String, String) CreateUser(String, String, String)

電子メール アドレスを指定して新しいユーザーをデータ ストアに追加します。Adds a new user with a specified email address to the data store.

public:
 static System::Web::Security::MembershipUser ^ CreateUser(System::String ^ username, System::String ^ password, System::String ^ email);
public static System.Web.Security.MembershipUser CreateUser (string username, string password, string email);
static member CreateUser : string * string * string -> System.Web.Security.MembershipUser
Public Shared Function CreateUser (username As String, password As String, email As String) As MembershipUser

パラメーター

username
String String String String

新しいユーザーのユーザー名。The user name for the new user.

password
String String String String

新規ユーザーのパスワード。The password for the new user.

email
String String String String

新しいユーザーの電子メール アドレス。The email address for the new user.

戻り値

新しく作成されたユーザーの MembershipUser オブジェクト。A MembershipUser object for the newly created user.

例外

ユーザーが作成されませんでした。The user was not created. StatusCode プロパティの MembershipCreateStatus 値を確認してください。Check the StatusCode property for a MembershipCreateStatus value.

次のコード例では、フォーム認証と ASP.NET のメンバーシップを使用するように構成の ASP.NET アプリケーションの新しいユーザーを作成します。The following code example creates a new user for an ASP.NET application configured to use forms authentication and ASP.NET membership. ユーザーが正常に作成されていない場合は、ユーザーにメッセージが表示されます。If the user is not created successfully, a message is displayed to the user. それ以外の場合、ユーザーは、アプリケーションのログイン ページにリダイレクトされます。Otherwise, the user is redirected to the login page for the application.

重要

この例には、潜在的なセキュリティ上の脅威がユーザー入力を受け付けるテキスト ボックスが含まれています。This example contains a text box that accepts user input, which is a potential security threat. 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 詳細については、「スクリプトによる攻略の概要」を参照してください。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>

注釈

CreateUser データ ストアに新しいユーザーを追加し、返します、MembershipUser新しく作成したユーザーのオブジェクト。CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. ユーザーの作成に失敗した場合、MembershipCreateUserExceptionがスローされます。If the user creation fails, a MembershipCreateUserException is thrown. 取得することができます、MembershipCreateStatus値から、StatusCodeのプロパティ、MembershipCreateUserExceptionユーザーの作成が失敗した理由を示します。You can retrieve a MembershipCreateStatus value from the StatusCode property of the MembershipCreateUserException that indicates why user creation failed.

参照を使用してメンバーシップ ユーザーが作成された後、MembershipUserそのユーザーの設定を変更できますが、そのユーザーのオブジェクトで、MembershipUserパブリック メソッドなどChangePasswordQuestionAndAnswerアプリケーション、 RequiresQuestionAndAnswertrue、またはプロパティの値を設定して、MembershipUserオブジェクトとそれらに渡す、UpdateUserメソッド。Once a membership user has been created and you have a reference to a MembershipUser object for that user, you can modify the settings for that user with the MembershipUser public methods, such as ChangePasswordQuestionAndAnswer for applications where RequiresQuestionAndAnswer is true, or by setting the property values of the MembershipUser object and passing them to the UpdateUser method.

アプリケーションのデータ ソースで、ユーザーが既に存在する場合は取得できます、MembershipUserで既存のユーザーに対するオブジェクト、GetUserメソッド。If a user already exists in the data source for the application, you can obtain a MembershipUser object for the existing user with the GetUser method.

すべてのパラメーター値は、先頭と末尾のスペースが切り捨てられます。Leading and trailing spaces are trimmed from all parameter values.

こちらもご覧ください

CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, MembershipCreateStatus)

プロパティ値を指定して新しいユーザーをデータ ストアに追加し、ユーザーの作成に成功したかどうか、または失敗の理由を示すステータス パラメーターを返します。Adds a new user with specified property values to the data store and returns a status parameter indicating that the user was successfully created or the reason the user creation failed.

public:
 static System::Web::Security::MembershipUser ^ CreateUser(System::String ^ username, System::String ^ password, System::String ^ email, System::String ^ passwordQuestion, System::String ^ passwordAnswer, bool isApproved, [Runtime::InteropServices::Out] System::Web::Security::MembershipCreateStatus % status);
public static System.Web.Security.MembershipUser CreateUser (string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, out System.Web.Security.MembershipCreateStatus status);
static member CreateUser : string * string * string * string * string * bool *  -> System.Web.Security.MembershipUser
Public Shared Function CreateUser (username As String, password As String, email As String, passwordQuestion As String, passwordAnswer As String, isApproved As Boolean, ByRef status As MembershipCreateStatus) As MembershipUser

パラメーター

username
String String String String

新しいユーザーのユーザー名。The user name for the new user.

password
String String String String

新規ユーザーのパスワード。The password for the new user.

email
String String String String

新しいユーザーの電子メール アドレス。The email address for the new user.

passwordQuestion
String String String String

メンバーシップ ユーザーに対するパスワードの質問。The password-question value for the membership user.

passwordAnswer
String String String String

メンバーシップ ユーザーに対するパスワードの解答。The password-answer value for the membership user.

isApproved
Boolean Boolean Boolean Boolean

新しいユーザーのログオンを承認するかどうかを示すブール値。A Boolean that indicates whether the new user is approved to log on.

status
MembershipCreateStatus MembershipCreateStatus MembershipCreateStatus MembershipCreateStatus

ユーザーの作成に成功したかどうか、または失敗の理由を示す MembershipCreateStatusA MembershipCreateStatus indicating that the user was created successfully or the reason that creation failed.

戻り値

新しく作成されたユーザーの MembershipUser オブジェクト。A MembershipUser object for the newly created user. ユーザーが作成されなかった場合、このメソッドは null を返します。If no user was created, this method returns null.

次のコード例では、フォーム認証と ASP.NET のメンバーシップを使用するように構成の ASP.NET アプリケーションの新しいユーザーを作成します。The following code example creates a new user for an ASP.NET application configured to use forms authentication and ASP.NET membership. ユーザーが正常に作成されていない場合は、ユーザーにメッセージが表示されます。If the user is not created successfully, a message is displayed to the user. それ以外の場合、ユーザーは、アプリケーションのログイン ページにリダイレクトされます。Otherwise, the user is redirected to the login page for the application.

重要

この例には、潜在的なセキュリティ上の脅威がユーザー入力を受け付けるテキスト ボックスが含まれています。This example contains a text box that accepts user input, which is a potential security threat. 既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 詳細については、「スクリプトによる攻略の概要」を参照してください。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)
{
  // 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 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)

  ' 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 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" />
  <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>

注釈

CreateUser データ ストアに新しいユーザーを追加し、返します、MembershipUser新しく作成したユーザーのオブジェクト。CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. 取得することができます、ユーザーの作成に失敗した場合、MembershipCreateStatus値から、statusユーザーの作成が失敗した理由を示す出力パラメーター。If the user creation fails, you can retrieve a MembershipCreateStatus value from the status output parameter that indicates why user creation failed.

CreateUserメソッドが返すnull場合password空の文字列またはnullusername空の文字列またはnullまたはコンマ (,) を含んでpasswordQuestionnull空の文字列で、またはpasswordAnswerないnull空の文字列が含まれています。The CreateUser method will return null if password is an empty string or null, username is an empty string or null or contains a comma (,), passwordQuestion is not null and is an empty string, or passwordAnswer is not null and contains an empty string.

参照を使用してメンバーシップ ユーザーが作成された後、MembershipUserそのユーザーの設定を変更できますが、そのユーザーのオブジェクトで、MembershipUserパブリック メソッドのプロパティ値を設定し、MembershipUserオブジェクトを渡す、MembershipUserオブジェクトをUpdateUserメソッド。Once a membership user has been created and you have a reference to a MembershipUser object for that user, you can modify the settings for that user with the MembershipUser public methods and by setting the property values of the MembershipUser object and then passing the MembershipUser object to the UpdateUser method.

アプリケーションのデータ ソースで、ユーザーが既に存在する場合は取得できます、MembershipUserで既存のユーザーに対するオブジェクト、GetUserメソッド。If a user already exists in the data source for the application, you can obtain a MembershipUser object for the existing user with the GetUser method.

すべての文字列パラメーターの値から、先頭と末尾のスペースが切り捨てられます。Leading and trailing spaces are trimmed from all string parameter values.

こちらもご覧ください

CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus) CreateUser(String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

指定したプロパティ値と一意の ID で新しいユーザーをデータ ストアに追加し、ユーザーの作成に成功したかどうか、または失敗の理由を示すステータス パラメーターを返します。Adds a new user with specified property values and a unique identifier to the data store and returns a status parameter indicating that the user was successfully created or the reason the user creation failed.

public:
 static System::Web::Security::MembershipUser ^ CreateUser(System::String ^ username, System::String ^ password, System::String ^ email, System::String ^ passwordQuestion, System::String ^ passwordAnswer, bool isApproved, System::Object ^ providerUserKey, [Runtime::InteropServices::Out] System::Web::Security::MembershipCreateStatus % status);
public static System.Web.Security.MembershipUser CreateUser (string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status);
static member CreateUser : string * string * string * string * string * bool * obj *  -> System.Web.Security.MembershipUser
Public Shared Function CreateUser (username As String, password As String, email As String, passwordQuestion As String, passwordAnswer As String, isApproved As Boolean, providerUserKey As Object, ByRef status As MembershipCreateStatus) As MembershipUser

パラメーター

username
String String String String

新しいユーザーのユーザー名。The user name for the new user.

password
String String String String

新規ユーザーのパスワード。The password for the new user.

email
String String String String

新しいユーザーの電子メール アドレス。The email address for the new user.

passwordQuestion
String String String String

メンバーシップ ユーザーに対するパスワードの質問。The password-question value for the membership user.

passwordAnswer
String String String String

メンバーシップ ユーザーに対するパスワードの解答。The password-answer value for the membership user.

isApproved
Boolean Boolean Boolean Boolean

新しいユーザーのログオンを承認するかどうかを示すブール値。A Boolean that indicates whether the new user is approved to log on.

providerUserKey
Object Object Object Object

メンバーシップ データ ストアに格納する必要があるユーザーのユーザー ID。The user identifier for the user that should be stored in the membership data store.

status
MembershipCreateStatus MembershipCreateStatus MembershipCreateStatus MembershipCreateStatus

ユーザーの作成に成功したかどうか、または失敗の理由を示す MembershipCreateStatusA MembershipCreateStatus indicating that the user was created successfully or the reason creation failed.

戻り値

新しく作成されたユーザーの MembershipUser オブジェクト。A MembershipUser object for the newly created user. ユーザーが作成されなかった場合、このメソッドは null を返します。If no user was created, this method returns null.

注釈

CreateUser データ ストアに新しいユーザーを追加し、返します、MembershipUser新しく作成したユーザーのオブジェクト。CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. 取得することができます、ユーザーの作成に失敗した場合、MembershipCreateStatus値から、statusユーザーの作成が失敗した理由を示す出力パラメーター。If the user creation fails, you can retrieve a MembershipCreateStatus value from the status output parameter that indicates why user creation failed. 使用してデータベースでは、主キーの値など、ユーザーの一意の識別子を指定することができます、providerUserKeyパラメーター。You can specify a unique identifier for the user, such as a primary key value for a database, by using the providerUserKey parameter.

CreateUserメソッドが返すnull場合password空の文字列またはnullusername空の文字列またはnullまたはコンマ (,) が含まれているpasswordQuestionnull空が含まれています文字列、またはpasswordAnswerないnull空の文字列が含まれています。The CreateUser method will return null if password is an empty string or null, username is an empty string or null or contains a comma (,), passwordQuestion is not null and contains an empty string, or passwordAnswer is not null and contains an empty string.

参照を使用してメンバーシップ ユーザーが作成された後、MembershipUserそのユーザーの設定を変更できますが、そのユーザーのオブジェクトで、MembershipUserパブリック メソッドのプロパティ値を設定し、MembershipUserオブジェクトを渡す、MembershipUserオブジェクトをUpdateUserメソッド。Once a membership user has been created and you have a reference to a MembershipUser object for that user, you can modify the settings for that user with the MembershipUser public methods and by setting the property values of the MembershipUser object and then passing the MembershipUser object to the UpdateUser method.

アプリケーションのデータ ソースで、ユーザーが既に存在する場合は取得できます、MembershipUserで既存のユーザーに対するオブジェクト、GetUserメソッド。If a user already exists in the data source for the application, you can obtain a MembershipUser object for the existing user with the GetUser method.

すべての文字列パラメーターの値から、先頭と末尾のスペースが切り捨てられます。Leading and trailing spaces are trimmed from all string parameter values.

こちらもご覧ください

適用対象