ProfileGroupBase 類別

定義

提供群組 ASP.NET 設定檔屬性值的不具型別存取。

public ref class ProfileGroupBase
public class ProfileGroupBase
type ProfileGroupBase = class
Public Class ProfileGroupBase
繼承
ProfileGroupBase

範例

下列Web.config檔案會指定使用者設定檔,其中包含一 Address 組名稱為 的屬性。 針對 Profile 目前 HttpContext 屬性產生的群組屬性前面會加上組名,例如 Profile.Address.Street 。 第二個範例顯示儲存和擷取已設定配置檔案屬性的 ASP.NET 網頁。

<configuration>
  <connectionStrings>
    <add name="SqlServices" connectionString=
      "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
  </connectionStrings>

  <system.web>
    <authentication mode="Forms" >
      <forms loginUrl="login.aspx"
        name=".ASPXFORMSAUTH" />
    </authentication>

    <authorization>
      <deny users="?" />
    </authorization>

    <membership defaultProvider="SqlProvider"
      userIsOnlineTimeWindow="15">
      <providers>
        <clear />
        <add
          name="SqlProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="SqlServices"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="true"
          requiresUniqueEmail="false"
          passwordFormat="Hashed"
          applicationName="MyApplication" />
      </providers>
    </membership>

    <profile enabled="true" defaultProvider="SqlProvider">
      <providers>
        <add
          name="SqlProvider"
          connectionStringName="SqlServices"
          applicationName="MyApplication"
          type="System.Web.Profile.SqlProfileProvider" />
      </providers>

      <properties>
        <add name="ZipCode" />
        <group name="Address">
          <add name="Street" />
          <add name="City" />
          <add name="State" />
          <add name="CountryOrRegion" />
        </group>
      </properties>
    </profile>
  </system.web>
</configuration>

下列程式碼範例顯示 ASP.NET 網頁,可讀取及設定為使用者設定檔指定的群組屬性。

重要

此範例包含接受使用者輸入的文字方塊,這是潛在的安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。

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

public void Page_Load()
{
  if (!IsPostBack)
  {
    StreetTextBox.Text          = Profile.Address.Street;
    CityTextBox.Text            = Profile.Address.City;
    StateTextBox.Text           = Profile.Address.State;
    CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion;
    ZipCodeTextBox.Text         = Profile.ZipCode;
  }
}

public void UpdateButton_OnClick(object sender, EventArgs args)
{
  Profile.Address.Street          = StreetTextBox.Text;
  Profile.Address.City            = CityTextBox.Text;
  Profile.Address.State           = StateTextBox.Text;
  Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text;
  Profile.ZipCode                 = ZipCodeTextBox.Text;
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
    <tr>
      <td>Street Address</td>
      <td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
    </tr>
    <tr>
      <td>City</td>
      <td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
    </tr>
    <tr>
      <td>State</td>
      <td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
    </tr>
    <tr>
      <td>Zip Code</td>
      <td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
    </tr>
    <tr>
      <td>Country</td>
      <td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
    </tr>
  </table>
  <asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</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">

Public Sub Page_Load()
  If Not IsPostBack Then
    StreetTextBox.Text          = Profile.Address.Street
    CityTextBox.Text            = Profile.Address.City
    StateTextBox.Text           = Profile.Address.State
    CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion
    ZipCodeTextBox.Text         = Profile.ZipCode
  End If
End Sub

Public Sub UpdateButton_OnClick(sender As Object, args As EventArgs)
  Profile.Address.Street          = StreetTextBox.Text
  Profile.Address.City            = CityTextBox.Text
  Profile.Address.State           = StateTextBox.Text
  Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text
  Profile.ZipCode                 = ZipCodeTextBox.Text
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
    <tr>
      <td>Street Address</td>
      <td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
    </tr>
    <tr>
      <td>City</td>
      <td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
    </tr>
    <tr>
      <td>State</td>
      <td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
    </tr>
    <tr>
      <td>Zip Code</td>
      <td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
    </tr>
    <tr>
      <td>Country</td>
      <td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
    </tr>
  </table>
  <asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</form>

</body>
</html>

備註

類別 ProfileGroupBase 是由 ASP.NET 用來在目前 HttpContext 的 屬性中 Profile 建立群組屬性。 當屬性指定為屬性群組時,使用 profile (ASP.NET Settings Schema) 之屬性的 group Element ,ASP.NET 會為群組中的每個屬性建立具有強型別存取子的新類別。 新類別會 ProfileGroupBase 繼承基類。 新類別的強型別存取子會呼叫 GetPropertyValue 基類的 ProfileGroupBaseSetPropertyValue 方法,分別擷取和設定配置檔案屬性值。

會將 ProfileGroupBase 呼叫傳遞給 取得和設定屬性值給繼承 ProfileBase 提供給 Init 類別方法之 類別的 ProfileGroupBase 類別。 ProfileBase如需行為、例外狀況等的詳細資訊,請參閱 類別。

此類別並非要從您的程式碼建立。

建構函式

ProfileGroupBase()

建立 ProfileGroupBase 類別的執行個體。

屬性

Item[String]

取得或設定由屬性名稱索引的群組設定檔屬性值。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetPropertyValue(String)

取得群組設定檔屬性的值。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Init(ProfileBase, String)

ASP.NET 用於初始化群組設定檔屬性值和資訊。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
SetPropertyValue(String, Object)

設定群組設定檔屬性的值。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱