次の方法で共有


ProfileGroupBase.SetPropertyValue(String, Object) メソッド

定義

グループ化されたプロファイル プロパティの値を設定します。

public:
 void SetPropertyValue(System::String ^ propertyName, System::Object ^ propertyValue);
public void SetPropertyValue (string propertyName, object propertyValue);
member this.SetPropertyValue : string * obj -> unit
Public Sub SetPropertyValue (propertyName As String, propertyValue As Object)

パラメーター

propertyName
String

設定対象のグループ化されたプロパティの名前。

propertyValue
Object

グループ化されたプロパティに代入する値。

次の ASP.NET ページでは、ユーザー プロファイルに指定されたグループ化されたプロパティを読み取って設定します。 ユーザー プロファイルのグループ化されたプロパティを指定する Web.config ファイルの例については、 クラスに指定されている例を ProfileGroupBase 参照してください。

重要

この例には、セキュリティ上の脅威となる可能性があるユーザー入力を受け入れるテキスト ボックスが含まれています。 既定では、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>

注釈

ASP.NET は、 クラスを ProfileBase 使用して、ユーザー プロファイルに使用されるクラスを作成します。 ユーザー プロファイルが有効になっているアプリケーションを起動すると、ASP.NET は、 クラスから継承する 型 ProfileCommonの新しいクラスを ProfileBase 作成します。 厳密に型指定されたアクセサーは、profile 要素 (ASP.NET 設定スキーマ) 構成セクションで定義されているグループとプロパティごとに クラスに追加ProfileCommonされます。 クラスの ProfileCommon 厳密に型指定されたアクセサーは、 メソッドを SetPropertyValue 呼び出して、データ ソースに ProfileProvider 格納される にグループ化されたプロパティ値を渡します。

メソッドを SetPropertyValue 使用して、アプリケーションのユーザー プロファイルのグループ化されたプロパティに名前で値を割り当てることができます。 値は として object, 型指定され、型チェックはコンパイル時ではなく実行時に実行されます。 プロファイル プロパティの値に厳密に型指定されたアクセス権を持つ場合は、グループ化されたプロパティに、プロパティのグループの Profile メンバーとして名前でアクセスできます (例: Profile.Address.City)。

適用対象

こちらもご覧ください