ProfileBase コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


例外の種類 | 条件 |
---|---|
System.Configuration.Provider.ProviderException | |
System.Configuration.ConfigurationErrorsException | Web.config ファイルの profile セクションで指定されたプロパティの型を作成できませんでした。 または Web.config ファイルの profile セクションで、いずれかのプロパティの allowAnonymous 属性が true に設定され、<anonymousIdentification> 要素の enabled 属性が false に設定されています。 または Web.config ファイルの profile セクションで、いずれかのプロパティの serializeAs 属性が Binary に設定され、指定された type の IsSerializable プロパティが false を返します。 または プロファイル プロパティの provider 属性を使用して指定されたプロバイダの名前が、Providers コレクションに見つかりませんでした。 または プロファイル プロパティに対して指定された type が見つかりませんでした。 または プロファイルのプロパティが、profile セクションの inherits 属性で指定された基本クラスのプロパティ名と一致する名前で指定されています。 |

ASP.NET では、ProfileBase クラスを使用して、ユーザー プロファイルに対して使用されるクラスを作成します。ユーザー プロファイルが有効にされたアプリケーションを起動すると、ASP.NET によって、ProfileBase クラスを継承する ProfileCommon 型の新しいクラスが作成されます。profile 構成セクションに定義されているそれぞれのプロパティに対して、厳密に型指定されたアクセサが ProfileCommon クラスに追加されます。ProfileCommon クラスの厳密に型指定されたアクセサは、ProfileBase 基本クラスの GetPropertyValue メソッドおよび SetPropertyValue メソッドを呼び出して、プロファイルのプロパティ値の取得および設定をそれぞれ行います。ProfileCommon クラスのインスタンスは、ASP.NET アプリケーションの Profile プロパティ値として設定されます。
![]() |
---|
Profile プロパティに格納されるクラスの生成に使用される基本クラスは、構成ファイルの profile セクションの inherits 属性を使用してオーバー ライドできます。この場合、ProfileBase 基本クラスから継承するカスタム クラスを指定します。 |
このコンストラクタは、アプリケーション コードで使用するためのものではありません。ユーザー プロファイルのインスタンスを作成するには、Create メソッドを使用します。

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 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 プロパティを読み込んだり、設定したりします。
<%@ 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>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ProfileBase コンストラクタのページへのリンク