March 8, 2021
Hot Topics:

The ASP.NET 2.0 Provider Model

  • By Dino Esposito
  • Send Email »
  • More Articles »

Provider Model Implementation

The implementation of the provider model consists of two distinct elements: the configuration layer and the storage layer. The configuration layer provides information for identifying and instantiating the physical provider object that manages the stored data. The storage layer is the physical entity that stores and manages the data. Depending on the feature, it can be Active Directory, an Oracle or SQL Server table, or an XML file.

Let's briefly review the characteristics of the provider model implementation in a common scenario: managing the user's profile, the set of personal information that each user keeps private.

The configuration layer provides a strongly typed model to get and set property values for the user profile object. The user profile object is represented with a collection of typed properties expressed in the web.config file as follows:

        <add name="BackColor" type="string" />
      <add name="ForeColor" type="string" />

The HTTP runtime parses the information above and creates a class like the following:

namespace ASP
   public class HttpProfile : HttpProfileBase
      public virtual string BackColor 
         get {(string) GetPropertyValue("BackColor");}
         set {SetPropertyValue("BackColor", value);}
      public virtual string ForeColor 
         get {(string) GetPropertyValue("ForeColor");}
         set {SetPropertyValue("ForeColor", value);}

The class is compiled on the fly and added to the application's AppDomain. An instance of the class is also exposed through the Profile property on the HttpContext class. The user profile object is filled with stored data when the request starts, and any modified values are restored upon exit. Reading and writing are operations the user profile providers perform.

ASP.NET 2.0 comes with two user profile providers. Each uses a different data engine. The default provider uses an Access database; the other provider is for SQL Server. You also can write custom providers. The provider writes data into the database of choice and is responsible for the final schema of the data. A user profile provider must be able to either serialize the type (by using XML serialization and binary object serialization, for example) or know how to extract significant information from it.

Provider Model in ASP.NET 2.0

At its core, the ASP.NET 2.0 provider infrastructure allows customers to extend some of the out-of-the-box system functionality and change the underlying implementation while keeping the top-level interface intact. Providers are relatively simple components with as few methods and properties as possible.

Other providers (for example, the membership provider) perform different tasks, such as creating a new user, deleting existing users, or validating a given user. However, no matter the operations performed, the provider supplies a common and immutable programming interface for tasks that helper classes perform—tasks that the client doesn't know in advance and that can work with any sort of storage medium.

As a result, the provider model in ASP.NET 2.0 has two key benefits:

  1. It makes the whole infrastructure much more resilient and flexible.
  2. It enables developers to port ASP.NET 2.0 into portions of their existing infrastructures that were developed for version 1.x easily. In this sense, it promotes reusability and smoothes migration.

About the Author

Dino Esposito is Wintellect's ADO.NET expert and a trainer and consultant based in Rome, Italy. He runs the Cutting Edge column for MSDN Magazine and is a regular contributor to MSDN News, Visual C++ Developers Journal, and SQL Server Magazine.

Page 3 of 3

This article was originally published on July 14, 2004

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date