Accessing Profiles from Components

You can access the Profile object from within a component by referring to the HttpContext.Profile property. However, you must cast the value of this property to an instance of the ProfileCommon object before you access its properties.

For example, the web configuration file in Listing 28.37 defines a Profile property named firstName.

Listing 28.37. Web.Config

images

The component in Listing 28.38 grabs the value of the firstName Profile property. The Profile object retrieved from the current HttpContext object must be typecast to a ProfileCommon object.

Listing 28.38. App_Code\ProfileComponent.cs

Warning

To avoid ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.