Introduction to ASP.NET 2.0 Provider Model
 
Published: 30 May 2007
Abstract
The provider model defines an easy plug-and-play architecture in Microsoft .NET. This article discusses ASP.NET's new features, like Membership, Personalization, and Profile.
by Joydip Kanjilal
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26197/ 58

Introduction

The new version of ASP.NET, i.e., ASP.NET 2.0 offers a wide range of features that are an improvement on its earlier counterpart, ASP.NET 1.x. It has enhanced the support for administration, user and roles management, extensibility, security and performance, to name a few. One of such new features is the ASP.NET 2.0 Provider Model. The provider model defines an easy plug-and-play architecture in Microsoft .NET. This article discusses ASP.NET's new features, like Membership, Personalization, and Profile.

The Provider Model of ASP.NET 2.0

You no longer have to depend on the web.config file (the application’s configuration file) for defining roles in your application. With ASP.NET 2.0 around, you have support for Membership and Role provider classes, like, the SqlMembershipProvider and SqlRoleProvider. However, the only constraint is that these are designed to work with SQL Server only. No worries; you can extend these classes to create your own custom provider implementations with support for any data store. We would learn more on Providers and their types in the sections to follow.

The ASP.NET Provider Model provides a pluggable architecture for working with providers. You can have the flexibility of using the custom providers; you can even implement your own providers in your applications. Well, what is a provider, anyway? The applications need some way of storing states, either in the temporary main memory or in a persistent manner in the database. "A provider is a software module that provides a uniform interface between a service and a data source. Providers abstract physical storage media, in much the same way that device drivers abstract physical hardware devices."

The Membership and the Role Management Providers follow the provider pattern through the usage of an interface for a contract based approach. The base class for all the providers in such a pattern is the ProviderBase abstract class. All the other providers are actually inherited from this ProviderBase abstract class. The MembershipProvider and the RoleProvider classes that inherit the ProviderBase class are also abstract classes. David Hayden says, "the theory of the pattern is that it allows us to define a well-documented, easy-to-understand API, such as our new Whidbey Membership API's, but at the same time give developers complete control over the internals of what occurs when those API's are called."

Objectives of the ASP.NET 2.0 Provider Model

The following lists the basic objectives of the ASP.NET 2.0 Provider Model.

·         Facilitate designing and developing custom providers seamlessly

·         Promotes flexibility, re-usability and extensibility in ASP.NET state storage  

Benefits of the ASP.NET 2.0 Provider Model

The Provider Model offers benefits in more ways than one. These are as follows.

·         It can be used with the default implementation and customized too.

·         Provides a distinct isolation of code and the back-end implementation.

·         Facilitates isolation of tasks within the project team members.

The ProviderBase class

The following is the list of the methods and properties of the ProviderBase class in the ASP.NET 2.0 Provider Model.

·         Name

·         Description

·         Initialize()

·         ProviderBase()  This is the constructor for the ProviderBase class.

The ProviderBase class is present in the System.Configuration.Provider namespace. This class contains two properties and two methods. The following is the source code for this class.

Listing 1

public class ProviderBase
{
  public virtual string Name
  {
    get;
  }
  public virtual string Description
  {
    get;
  }
  public virtual void Initialize(string name, NameValueCollection config);
}     

The "Name" property implies the name of the provider while the "Description" property relates to the description of the provider.

We will discuss more on the various providers in the ASP.NET Provider Model in the sections that follow.

The Providers in the ASP.NET Provider Model

The following are the built-in providers of the ASP.NET Provider Model.

·         Membership Providers

·         Role Management Providers

·         Profile Providers

·         Site Map Providers

·         Session State Providers

·         Web Event Providers

·         Web Parts Personalization Providers

·         Protected Configuration Providers

The Membership Provider

According to MSDN, "ASP.NET membership gives you a built-in way to validate and store user credentials. ASP.NET membership therefore helps you manage user authentication in your Web sites." You can know more on how Membership in ASP.NET works here. With ASP.NET 2.0, user management and roles administration has been simplified a lot. The Membership Provider or the Membership API that ships with ASP.NET 2.0 is used to manage the users of the application and their respective roles. It is extensible, but can work with SQL Server database and Active Directory. However, you can extent this API so that it can work with other databases as well.

The Roles Provider

A Role Provider is responsible for retrieval and storage of roles information to and from a data store. You have the SqlRoleProvider that is responsible for storing roles information in the SQL Server database. You can however, extend this class to create your custom implementation and store roles information in any data store.

Profile Providers

Profile Providers can be used to store user's profile information. According to MSDN, "Profile providers provide the interface between ASP.NET's profile service and profile data sources." Actually, the Profile provider in the ASP.NET 2.0 Provider Model is represented by the ProfileProvider class. Note all these provider abstract classes extend the ProviderBase abstract class in the ASP.NET 2.0 Provider Model.

Custom Providers

Custom Providers are those that you create generally by extending the existing providers to suit your specific requirements. The following are the benefits of creating Custom Providers.

·         Storage of membership information across any database or other data sources that are not supported by default

·         Managing the membership information as per your own schema

References       

Conclusion

This article has had a look at the Provider Model in ASP.NET 2.0 and the related concepts. It has also discussed what providers are, the types of providers and custom providers. You are free to use these providers or use your own Custom Providers to suit your needs in your web applications. I will discuss implementation of Custom Providers in future articles in this series.



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-03-02 12:38:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search