Programming Microsoft ASP.NET 4 - Dino Esposito [154]
%Windows%\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Otherwise, the path is
C:\Users\...\AppData\Local\Temp\Temporary ASP.NET Files
You can programmatically find out the real path being used by reading the value of the following expression:
HttpRuntime.CodegenDir
You can do that by placing a breakpoint somewhere in the page startup code and evaluating the expression in a Visual Studio QuickWatch window.
Using Collection Types
In the previous example, we worked with single, scalar values. However, the personalization engine fully supports more advanced scenarios, such as using collections or custom types. Let’s tackle collections first. The following code demonstrates a Locations property that is a collection of strings:
Nonscalar values such as collections and arrays must be serialized to fit in a data storage medium. The serializeAs attribute simply specifies how. As mentioned, acceptable values are String, Xml, Binary, and ProviderSpecific. If the serializeAs attribute is not present in the Using Custom Types serializeAs="Binary" /> The assembly that contains the custom type must be available to the ASP.NET application. You obtain this custom type by placing the assembly in the application’s Bin directory or by registering it within the global assembly cache (GAC). Grouping Properties ... Two properties have been declared children of the Metrics group. This means that from now on any access to Speed or Temperature passes through the Metrics name, as shown here: var windSpeedDisplayText = String.Format("{0} {1}", windSpeed, Profile.Metrics.Speed); The System.Web.UI.Page class doesn’t feature any Profile property. However, in a Web site project, the build machinery of ASP.NET generates an extra partial class where the Profile property is defined to just return HttpContext.Current.Profile. Note Default values are not saved to the persistence layer. Properties declared with a default value make their debut in the storage medium only when the application assigns them a value different from the default one. Definition of the Data Model in a WAP Project As you saw earlier, however, a profile class is not a plain old CLR class—it is expected, instead, to inherit from System.Web.Profile.ProfileBase. The parent class features two generic methods to read and write properties: GetPropertyValue and SetPropertyValue. This is the real code that ultimately retrieves
You can use a custom type with the ASP.NET personalization layer as long as you mark it as a serializable type. You simply author a class and compile it down to an assembly. The name of the assembly is added to the type information for the profile property:
The
In a WAP project, you can choose between a weakly typed and strongly typed approach. The simplest approach (but most effective as well?) is the weak typing approach. In this case, you do exactly the same as you would do in a Web site project. The only difference is that you have no Profile property on the Page class and no dynamically built profile class.