ProfileBase クラスとは? わかりやすく解説

ProfileBase クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

プロファイルプロパティ値と情報への型指定しないアクセス提供します

名前空間: System.Web.Profile
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class ProfileBase
    Inherits SettingsBase
public class ProfileBase : SettingsBase
public ref class ProfileBase : public
 SettingsBase
public class ProfileBase extends SettingsBase
public class ProfileBase extends
 SettingsBase
解説解説

ASP.NET では、ProfileBase クラス使用してユーザー プロファイルに対して使用されるクラス作成しますユーザー プロファイル有効にされたアプリケーション起動すると、ASP.NET によって、ProfileBase クラス継承する ProfileCommon 型の新しクラス作成されます。profile 構成セクション定義されているそれぞれのプロパティに対して厳密に指定されアクセサProfileCommon クラス追加されます。ProfileCommon クラス厳密に指定されアクセサは、ProfileBase 基本クラスの GetPropertyValue メソッドおよび SetPropertyValue メソッド呼び出してプロファイルプロパティ値の取得および設定それぞれ行いますProfileCommon クラスインスタンスは、ASP.NET アプリケーションProfile プロパティ値として設定されます。

ASP.NET アプリケーションユーザー プロファイルインスタンス作成するには、Create メソッド使用お勧めます。

継承時の注意 カスタムプロファイル実装は、ProfileBase 抽象クラス継承しprofile 構成要素指定されないプロパティユーザー プロファイル定義することで作成できますユーザー プロファイルカスタム型を Web.config ファイル内で指定するには、次の例に示すように、profile 構成要素inherits 属性使用しますEmployeeProfile クラスコードは、このトピックの「使用例」にあります

<profile inherits="Samples.AspNet.Profile.EmployeeProfile"
  defaultProvider="SqlProvider">
  <providers>
    <clear />
    <add
      name="SqlProvider"
      type="System.Web.Profile.SqlProfileProvider" 
      connectionStringName="SqlServices" 
      description="SQL Profile Provider for Sample"/> 
    <add
      name="EmployeeInfoProvider"
      type="System.Web.Profile.SqlProfileProvider" 
      connectionStringName="SqlServices" 
      description="SQL Profile Provider for Employee Info"/> 
  </providers>

  <properties>
    <add name="GarmentSize" />
  </properties>
</profile>
使用例使用例

string 型の ZipCode プロパティおよび StringCollection 型の RecentSearchList プロパティ含んだユーザー プロファイル指定する Web.config のコード例次に示します生成される現在の HttpContext の Profile プロパティは、指定されている各プロパティに対して厳密に指定されアクセサ持ちます

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

  <system.web>
    <anonymousIdentification enabled="true" />

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

      <properties>
        <add name="ZipCode" allowAnonymous="true" />
        <add name="RecentSearchList"
          type="System.Collections.Specialized.StringCollection"
          serializeAs="Xml"
          allowAnonymous="true" />
      </properties>
    </profile>
  </system.web>
</configuration>

ユーザー プロファイルに対して指定されZipCode プロパティ読み込んだり、設定したりする ASP.NET ページコード例次に示します

<%@ Page Language="VB" %>
<script runat="server">

Public Sub Page_PreRender()

  If Profile.ZipCode = Nothing Then
    PersonalizePanel.Visible = False
    GetZipCodePanel.Visible = True
  Else
    ZipCodeLabel.Text = Profile.ZipCode

    ' Get personalized information for zip code here.

    PersonalizePanel.Visible = True
    GetZipCodePanel.Visible = False
  End If

End Sub

Public Sub ChangeZipCode_OnClick(sender As
 Object, args As EventArgs)
  ZipCodeTextBox.Text = Profile.ZipCode
  Profile.ZipCode = Nothing

  PersonalizePanel.Visible = False
  GetZipCodePanel.Visible = True
End Sub

Public Sub EnterZipCode_OnClick(sender As
 Object, args As EventArgs)
  Profile.ZipCode = ZipCodeTextBox.Text
End Sub

</script>
<html>
<head>
<title>Home Page</title>
</head>
<body>

<form runat="server">
  <table border=1 cellpadding=2 cellspacing=2>
    <tr>
      <td>
        <asp:Panel id="PersonalizePanel" runat="Server"
 Visible="False">
          Information for Zip Code: <asp:Label id="ZipCodeLabel"
 Runat="Server" /><BR>
          <!-- Information for Zip Code here. -->
          <BR>
          <asp:LinkButton id="ChangeZipCodeButton"
 Runat="Server" Text="Change Your
 Zip Code"
                          OnClick="ChangeZipCode_OnClick"
 />
        </asp:Panel>
        <asp:Panel id="GetZipCodePanel" runat="Server"
 Visible="False">
          You can personalize this page by entering your Zip Code: 
          <asp:TextBox id="ZipCodeTextBox" Columns=5
 MaxLength=5 runat="Server" />
          <asp:LinkButton id="EnterZipCodeButton"
 Runat="Server" Text="Go"
                          OnClick="EnterZipCode_OnClick"
 />
        </asp:Panel>
      </td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">

public void Page_PreRender()
{
  if (Profile.ZipCode == null)
  {
    PersonalizePanel.Visible = false;
    GetZipCodePanel.Visible = true;
  }
  else
  {
    ZipCodeLabel.Text = Profile.ZipCode;

    // Get personalized information for zip code here.

    PersonalizePanel.Visible = true;
    GetZipCodePanel.Visible = false;
  }
}

public void ChangeZipCode_OnClick(object sender,
 EventArgs args)
{
  ZipCodeTextBox.Text = Profile.ZipCode;
  Profile.ZipCode = null;

  PersonalizePanel.Visible = false;
  GetZipCodePanel.Visible = true;
}

public void EnterZipCode_OnClick(object sender,
 EventArgs args)
{
  Profile.ZipCode = ZipCodeTextBox.Text;
}

</script>
<html>
<head>
<title>Home Page</title>
</head>
<body>

<form runat="server">
  <table border=1 cellpadding=2 cellspacing=2>
    <tr>
      <td>
        <asp:Panel id="PersonalizePanel" runat="Server" Visible="False">
          Information for Zip Code: <asp:Label id="ZipCodeLabel"
 Runat="Server" /><BR>
          <!-- Information for Zip Code here. -->
          <BR>
          <asp:LinkButton id="ChangeZipCodeButton" Runat="Server"
 Text="Change Your Zip Code"
                          OnClick="ChangeZipCode_OnClick" />
        </asp:Panel>
        <asp:Panel id="GetZipCodePanel" runat="Server" Visible="False">
          You can personalize this page by entering your Zip Code:
 
          <asp:TextBox id="ZipCodeTextBox" Columns=5 MaxLength=5 runat="Server"
 />
          <asp:LinkButton id="EnterZipCodeButton" Runat="Server"
 Text="Go"
                          OnClick="EnterZipCode_OnClick" />
        </asp:Panel>
      </td>
    </tr>
  </table>
</form>

</body>
</html>

ProfileBase クラスから継承するクラス定義してカスタム プロファイル作成するコード例次に示しますカスタム プロファイルの型は、アプリケーションの Web.config ファイルにある profile 構成要素inherits 属性使用して指定します

Imports System
Imports System.Web.Profile

Namespace Samples.AspNet.Profile

  Public Class EmployeeProfile
    Inherits ProfileBase

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")>
 _
    Public Property Department As
 String
      Get
        Return MyBase.Item("EmployeeDepartment").ToString()
      End Get
      Set
        MyBase.Item("EmployeeDepartment")
 = value
      End Set
    End Property

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")>
 _
    Public Property Details As
 EmployeeInfo
      Get
        Return CType(MyBase.Item("EmployeeInfo"),
 EmployeeInfo)
      End Get
      Set
        MyBase.Item("EmployeeInfo")
 = value
      End Set
    End Property
  End Class

  Public Class EmployeeInfo
    Public Name As String
    Public Address As String
    Public Phone As String
    Public EmergencyContactName As String
    Public EmergencyContactAddress As String
    Public EmergencyContactPhone As String
  End Class

End Namespace
using System;
using System.Web.Profile;

namespace Samples.AspNet.Profile
{
  public class EmployeeProfile : ProfileBase
  {
    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public string Department
    {
      get { return base["EmployeeDepartment"].ToString();
 }
      set { base["EmployeeDepartment"]
 = value; }
    }

    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public EmployeeInfo Details
    {
      get { return (EmployeeInfo)base["EmployeeInfo"];
 }
      set { base["EmployeeInfo"]
 = value; }
    }

  }

  public class EmployeeInfo
  {
    public string Name;
    public string Address;
    public string Phone;
    public string EmergencyContactName;
    public string EmergencyContactAddress;
    public string EmergencyContactPhone;
  }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Configuration.SettingsBase
    System.Web.Profile.ProfileBase
       System.Web.Profile.DefaultProfile
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ProfileBase クラス」の関連用語

ProfileBase クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ProfileBase クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS