1

ASP.NET Webサイトでは、Web.Configセクションにいくつかの短い追加を行うだけで、自動で魔法のように配線されたプロパティをユーザープロファイルに追加できます。

たとえば、このようなXMLを使用します。

<profile>
  <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
  <properties>
    <add name="Name" allowAnonymous="true"/>
    <add name="VisitedOn" type="System.DateTime" allowAnonymous="true"/>
  </properties>
</profile>

あなたはこれを行う能力になってしまうでしょう。それ以上のコードを宣言する必要はありません。

Profile.Name = "Some Test Value";
Profile.VisitedOn = DateTime.Now;
Profile.Save();

ASP.NET Webアプリでこの機能を複製しようとしましたが、カスタムプロパティはもちろん、ベースプロファイル宣言も見つからないようです。

ただし、System.Web.Profile.DefaultProfile.Properties実際には、Web.Configで定義したカスタム宣言されたプロパティが含まれていることがわかりました。

では、どこが間違っているのでしょうか?Webアプリで自動配線プロパティを機能させるためのプロセスは何ですか?

4

1 に答える 1

1

The properties are created during the Compilation of ASP.NET Web Application when the first request arrives.

Ref: ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0

Profile properties defined in the Web.config file If profile properties are defined in the application's Web.config file, an assembly is generated that contains a profile object.

You can hook into this Compilation by writing a custom BuildProvider and registering the same. This build provider can be used for generating the auto wired properties.

于 2012-07-24T07:13:49.053 に答える