CreateUserWizard.MembershipProvider 屬性

定義

取得或設定成員資格提供者,可以呼叫它來建立使用者帳戶。Gets or sets the membership provider called to create user accounts.

public:
 virtual property System::String ^ MembershipProvider { System::String ^ get(); void set(System::String ^ value); };
[System.Web.UI.Themeable(false)]
public virtual string MembershipProvider { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.MembershipProvider : string with get, set
Public Overridable Property MembershipProvider As String

屬性值

String

用來建立使用者帳戶的 MembershipProviderThe MembershipProvider used to create user accounts. 預設為 EmptyThe default is Empty.

屬性

例外狀況

指定的成員資格提供者未在 Web.config 檔中定義。The specified membership provider is not defined in the Web.config file.

範例

下列程式碼範例需要 Web.config 檔的區段中所定義的成員資格提供者 <membership>The following code example requires membership providers defined in the <membership> section of the Web.config file. 以下是為小型公司中的每個部門定義成員資格提供者的 Web.config 檔案。The following is a Web.config file that defines membership providers for each division in a small company. 在此範例中,每個成員資格提供者都會指向 SQL Server 資料庫。For this example, each membership provider points to a SQL Server database.

<configuration>

<system.web>

<membership>

<providers>

<add name="accountingProvider"

type="System.Web.Security.SqlMembershipProvider,

System.Web, Version=2.0.3600.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a"

connectionStringName="LocalSqlServer"

enablePasswordRetrieval="false"

enablePasswordReset="true"

requiresQuestionAndAnswer="false"

applicationName="/"

requiresUniqueEmail="false"

passwordFormat="Hashed"

description="Stores and retrieves membership data from a Microsoft SQL Server database."

/>

<add name="manufacturingProvider"

type="System.Web.Security. SqlMembershipProvider,type="System.Web.Security. SqlMembershipProvider,

System.Web, Version=2.0.3600.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a"

connectionStringName="LocalSqlServer"

enablePasswordRetrieval="false"

enablePasswordReset="true"

requiresQuestionAndAnswer="false"

applicationName="/"

requiresUniqueEmail="false"

passwordFormat="Hashed"

description="Stores and retrieves membership data from a Microsoft SQL Server database."

/>

<add name="marketingProvider"

type="System.Web.Security. SqlMembershipProvider,type="System.Web.Security. SqlMembershipProvider,

System.Web, Version=2.0.3600.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a"

connectionStringName="LocalSqlServer"

enablePasswordRetrieval="false"

enablePasswordReset="true"

requiresQuestionAndAnswer="false"

applicationName="/"

requiresUniqueEmail="false"

passwordFormat="Hashed"

description="Stores and retrieves membership data from a Microsoft SQL Server database."

/>

<add name="salesProvider"

type="System.Web.Security. SqlMembershipProvider,type="System.Web.Security. SqlMembershipProvider,

System.Web, Version=2.0.3600.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a"

connectionStringName="LocalSqlServer"

enablePasswordRetrieval="false"

enablePasswordReset="true"

requiresQuestionAndAnswer="false"

applicationName="/"

requiresUniqueEmail="false"

passwordFormat="Hashed"

description="Stores and retrieves membership data from a Microsoft SQL Server database."

/>

</providers>

</membership>

</system.web>

</configuration>

下列程式碼範例會在建立使用者帳戶之前插入步驟,以判斷使用者所屬的組織部門。The following code example inserts a step before the user account is created to determine which division of an organization the user belongs to. 然後,它會將 MembershipProvider 提供者設定為該部門適當的提供者。It then sets the MembershipProvider provider to the appropriate provider for that division.

<%@ page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  void Createuserwizard1_NextButtonClick(object sender, EventArgs e)
  {
    if (Createuserwizard1.ActiveStepIndex==0)
    {
      Createuserwizard1.MembershipProvider =
        divisionList.SelectedValue;
      Createuserwizard1.CreateUserStep.Title =
        String.Format("Create your new {0} account.",
          divisionList.SelectedItem.Text);
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Untitled Page</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:createuserwizard id="Createuserwizard1" runat="server" onnextbuttonclick="Createuserwizard1_NextButtonClick">
          <wizardsteps>
            <asp:wizardstep runat="server" title="Choose your division">
              <p>
                Choose your division and click "Next".</p>
              <asp:dropdownlist runat="server" id="divisionList">
                <asp:listitem value="accountingProvider">
                  Accounting</asp:listitem>
                <asp:listitem value="manufacturingProvider">
                  Manufacturing</asp:listitem>
                <asp:listitem value="marketingProvider">
                  Marketing</asp:listitem>
                <asp:listitem value="salesProvider">
                  Sales</asp:listitem>
              </asp:dropdownlist>
            </asp:wizardstep>
            <asp:createuserwizardstep runat="server" title="Sign Up for Your New Account">
            </asp:createuserwizardstep>
          </wizardsteps>
        </asp:createuserwizard>
      </div>
    </form>
  </body>
</html>
<%@ page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Createuserwizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
    If Createuserwizard1.ActiveStepIndex = 0 Then
      Createuserwizard1.MembershipProvider = _
      divisionList.SelectedValue()
      Createuserwizard1.CreateUserStep.Title = _
        String.Format("Create your new {0} account.", _
          divisionList.SelectedItem.Text)
    End If
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Untitled Page</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:createuserwizard id="Createuserwizard1" runat="server" onnextbuttonclick="Createuserwizard1_NextButtonClick">
          <wizardsteps>
            <asp:wizardstep runat="server" title="Choose your division">
              <p>
                Choose your division and click "Next".</p>
              <asp:dropdownlist runat="server" id="divisionList">
                <asp:listitem value="accountingProvider">
                  Accounting</asp:listitem>
                <asp:listitem value="manufacturingProvider">
                  Manufacturing</asp:listitem>
                <asp:listitem value="marketingProvider">
                  Marketing</asp:listitem>
                <asp:listitem value="salesProvider">
                  Sales</asp:listitem>
              </asp:dropdownlist>
            </asp:wizardstep>
            <asp:createuserwizardstep runat="server" title="Sign Up for Your New Account">
            </asp:createuserwizardstep>
          </wizardsteps>
        </asp:createuserwizard>
      </div>
    </form>
  </body>
</html>

備註

MembershipProvider屬性包含 MembershipProvider 用來儲存使用者資訊之已定義類別成員資格提供者的名稱。The MembershipProvider property contains the name of the defined MembershipProvider class membership provider that is used to store the user information. 您可以藉由變更屬性的值,將使用者的成員資格資訊儲存在不同的資料存放區中 MembershipProviderYou can store membership information for users in different data stores by changing the value of the MembershipProvider property. MembershipProvider 屬性設定為時 Empty ,就會使用 Web.config 檔中定義的預設成員資格提供者。When the MembershipProvider property is set to Empty, the default membership provider defined in the Web.config file is used.

成員資格提供者是在一節的 Web.config 檔案中定義 <membership>Membership providers are defined in the Web.config file in the <membership> section.

這個屬性無法由佈景主題或樣式表主題設定。This property cannot be set by themes or style sheet themes. 如需詳細資訊,請參閱 ThemeableAttributeASP.NET 主題和外觀For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

適用於