Question

In an ASP.NET website it is possible with a few short additions to the Web.Config section to add auto-magically wired properties to the user profile.

So for example with some XML like this.

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

You would end up with the ability to do this. Without having to declare any further code.

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

I have attempted to duplicate this functionality in an ASP.NET Web App and can't even seem to find the base Profile declaration let alone the custom properties.

I have however found that System.Web.Profile.DefaultProfile.Properties does infact contain the custom declared properties I define in the Web.Config.

So where might I be going wrong? What is the process for getting auto wired properties in web apps working?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top