Membership.CreateUser 메서드

정의

데이터 저장소에 새 사용자를 추가합니다.Adds a new user to the data store.

오버로드

CreateUser(String, String)

데이터 저장소에 새 사용자를 추가합니다.Adds a new user to the data store.

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)

속성 값이 지정된 새 사용자를 데이터 저장소에 추가하고 사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 상태 매개 변수를 반환합니다.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)

속성 값이 지정되고 고유한 식별자를 가진 새 사용자를 데이터 저장소에 추가하고 사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 상태 매개 변수를 반환합니다.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)

데이터 저장소에 새 사용자를 추가합니다.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

새 사용자의 사용자 이름입니다.The user name for the new user.

password
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 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 자세한 내용은 Script Exploits Overview를 참조하세요.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이 throw 됩니다.If the user creation fails, a MembershipCreateUserException is thrown. 사용자를 만들지 못한 이유를 나타내는 MembershipCreateUserExceptionStatusCode 속성에서 MembershipCreateStatus 값을 검색할 수 있습니다.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이 throw 됩니다.Otherwise, a MembershipCreateUserException will be thrown.

모든 매개 변수 값에서 선행 및 후행 공백이 잘립니다.Leading and trailing spaces are trimmed from all parameter values.

추가 정보

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

새 사용자의 사용자 이름입니다.The user name for the new user.

password
String

새 사용자의 암호입니다.The password for the new user.

email
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 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 자세한 내용은 Script Exploits Overview를 참조하세요.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이 throw 됩니다.If the user creation fails, a MembershipCreateUserException is thrown. 사용자를 만들지 못한 이유를 나타내는 MembershipCreateUserExceptionStatusCode 속성에서 MembershipCreateStatus 값을 검색할 수 있습니다.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)

속성 값이 지정된 새 사용자를 데이터 저장소에 추가하고 사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 상태 매개 변수를 반환합니다.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 * MembershipCreateStatus -> 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

새 사용자의 사용자 이름입니다.The user name for the new user.

password
String

새 사용자의 암호입니다.The password for the new user.

email
String

새 사용자의 전자 메일 주소입니다.The email address for the new user.

passwordQuestion
String

멤버 자격 사용자의 암호 질문 값입니다.The password-question value for the membership user.

passwordAnswer
String

멤버 자격 사용자의 암호 대답 값입니다.The password-answer value for the membership user.

isApproved
Boolean

새 사용자에 대한 로그온이 승인되는지 여부를 나타내는 부울 값입니다.A Boolean that indicates whether the new user is approved to log on.

status
MembershipCreateStatus

사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 MembershipCreateStatus입니다.A 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 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 자세한 내용은 Script Exploits Overview를 참조하세요.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. 사용자 만들기가 실패 하는 경우 사용자를 만들지 못한 이유를 나타내는 status output 매개 변수에서 MembershipCreateStatus 값을 검색할 수 있습니다.If the user creation fails, you can retrieve a MembershipCreateStatus value from the status output parameter that indicates why user creation failed.

CreateUser 메서드는 password이 빈 문자열 이거나 null이거나 빈 문자열이 나 username 이거나 쉼표 (,)를 포함 하는 경우 null을 반환 하 고 nullpasswordQuestion 되지 않으며 빈 문자열 이거나 nullpasswordAnswer 없고 빈 문자열을 포함 합니다.nullThe 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)

속성 값이 지정되고 고유한 식별자를 가진 새 사용자를 데이터 저장소에 추가하고 사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 상태 매개 변수를 반환합니다.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 * MembershipCreateStatus -> 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

새 사용자의 사용자 이름입니다.The user name for the new user.

password
String

새 사용자의 암호입니다.The password for the new user.

email
String

새 사용자의 전자 메일 주소입니다.The email address for the new user.

passwordQuestion
String

멤버 자격 사용자의 암호 질문 값입니다.The password-question value for the membership user.

passwordAnswer
String

멤버 자격 사용자의 암호 대답 값입니다.The password-answer value for the membership user.

isApproved
Boolean

새 사용자에 대한 로그온이 승인되는지 여부를 나타내는 부울 값입니다.A Boolean that indicates whether the new user is approved to log on.

providerUserKey
Object

멤버 자격 정보 저장소에 저장되어야 하는 사용자 ID입니다.The user identifier for the user that should be stored in the membership data store.

status
MembershipCreateStatus

사용자가 만들어졌음을 나타내거나 사용자 만들기에 실패한 이유를 나타내는 MembershipCreateStatus입니다.A 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. 사용자 만들기가 실패 하는 경우 사용자를 만들지 못한 이유를 나타내는 status output 매개 변수에서 MembershipCreateStatus 값을 검색할 수 있습니다.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 메서드는 password이 빈 문자열 이거나 null이거나 빈 문자열이 나 username 이거나 쉼표 (,)를 포함 하는 경우 null을 반환 하 고 nullpasswordQuestion 되지 않으며 빈 문자열을 포함 하거나 null passwordAnswer 없고 빈 문자열을 포함 합니다.nullThe 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.

추가 정보

적용 대상