ProfileBase コンストラクター

定義

ProfileBase クラスのインスタンスを作成します。

public:
 ProfileBase();
public ProfileBase ();
Public Sub New ()

例外

Web.config ファイルの profile セクションの enabled 属性が false です。

Web.config ファイルの profile セクションで指定されたプロパティの型を作成できませんでした。

  • または -

Web.config ファイルの profile セクションで、いずれかのプロパティの allowAnonymous 属性が true に設定され、<anonymousIdentification> 要素の enabled 属性が false に設定されています。

  • または -

Web.config ファイルの profile セクションで、いずれかのプロパティの serializeAs 属性が Binary に設定され、指定された typeIsSerializable プロパティが false を返します。

  • または -

プロファイル プロパティの provider 属性を使用して指定されたプロバイダーの名前が、Providers コレクションに見つかりませんでした。

  • または -

プロファイル プロパティに対して指定された type が見つかりませんでした。

  • または -

プロファイルのプロパティが、profile セクションの inherits 属性で指定された基本クラスのプロパティ名と一致する名前で指定されています。

次のWeb.config ファイルは、型のプロパティと型stringのプロパティをZipCode含むユーザー プロファイルをRecentSearchList指定しますStringCollection。 現在HttpContextの生成されたProfileプロパティには、指定されたプロパティごとに厳密に型指定されたアクセサーがあります。

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

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

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

次の ASP.NET ページでは、ユーザー プロファイルに指定されたプロパティをZipCode読み取って設定します。

重要

この例には、セキュリティ上の潜在的な脅威であるユーザー入力を受け入れるテキスト ボックスが含まれています。 既定では、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_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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" 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="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_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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" 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>

注釈

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

注意

プロパティに格納されているProfileクラスの生成に使用される基本クラスは、構成ファイルの profile セクションの属性を使用してinheritsオーバーライドできます。 この場合は、基底クラスから継承するカスタム クラスを ProfileBase 指定します。

このコンストラクターは、アプリケーション コードから使用するためのものではありません。 ユーザー プロファイルのインスタンスを作成するには、メソッドを Create 使用します。

適用対象

こちらもご覧ください