CreateUserWizard.MembershipProvider 属性

定义

获取或设置调用的成员资格提供程序以创建用户帐户。

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

属性值

用于创建用户帐户的 MembershipProvider。 默认值为 Empty

属性

例外

指定的成员资格提供程序未在 Web.config 文件中定义。

示例

以下代码示例要求在 Web.config 文件的 <membership> 节中定义的成员身份提供程序。 下面是一个 Web.config 文件,该文件定义小公司中每个部门的成员资格提供程序。 对于此示例,每个成员资格提供程序指向 SQL Server 数据库。

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

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,

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,

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>

下面的代码示例在创建用户帐户之前插入一个步骤,以确定用户所属的组织划分。 然后,它将 MembershipProvider 提供程序设置为该分区的相应提供程序。

<%@ 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 类成员身份提供程序的名称。 可以通过更改 MembershipProvider 属性的值,将用户的成员身份信息存储在不同的数据存储中。 当 MembershipProvider 属性设置为 Empty时,将使用 Web.config 文件中定义的默认成员资格提供程序。

成员身份提供程序在 <membership> 部分中的 Web.config 文件中定义。

此属性不能由主题或样式表主题设置。 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和皮肤

适用于

另请参阅