Share via


ProfileGroupBase クラス

定義

ASP.NET プロファイル プロパティ値をグループ化するための、型指定しないアクセスを提供します。

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

次のWeb.config ファイルは、グループ名 が のプロパティのグループを含むユーザー プロファイルを指定します Address。 現在HttpContextの の プロパティに対してProfile生成されるグループ化されたプロパティの前には、グループ名 (例: Profile.Address.Street) が付けられます。 2 番目の例は、構成されたプロファイル プロパティを格納および取得する 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 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@ 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、現在HttpContextの の プロパティにグループ化されたプロパティを作成するために、ProfileASP.NET によって使用されます。 プロパティが 、プロファイルのプロパティの group 要素 (ASP.NET 設定スキーマ) を使用してプロパティのグループとして指定されている場合、ASP.NET は、グループ内の各プロパティに対して厳密に型指定されたアクセサーを持つ新しいクラスを作成します。 新しいクラスは基底クラスを ProfileGroupBase 継承します。 新しいクラスの厳密に型指定されたアクセサーは、基本クラスの メソッドと SetPropertyValue メソッドをProfileGroupBase呼び出GetPropertyValueして、それぞれプロファイル プロパティ値を取得および設定します。

ProfileGroupBase、 の呼び出しを渡して、 クラスの メソッドProfileGroupBaseに提供されるクラスをProfileBase継承するクラスにプロパティ値をInit取得および設定します。 動作、 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)

適用対象

こちらもご覧ください