11.1. The Membership Class

Probably the first exposure many of you had to the Membership feature was through the similarly named Membership class. This class is defined as a public static class, and the style of programming you use with it is meant to parallel other common ASP.NET classes such as Request, Response, and so on. Rather than having to muddle around trying to figure out how to get up and running with the feature, the idea is that after developers know of the Membership class, they can quickly access the functionality of the feature.

As with many provider-based features, the most important task the Membership class provides has already completed before any of your code does anything substantial with the feature. The previous chapter, on the provider model, showed how a static feature class is responsible for initializing a feature, including the instantiation and initialization of all providers associated with the feature. Because the Membership class is static, it performs initialization only once during the lifetime of an application. Furthermore, it instantiates only one instance of each configured MembershipProvider. So, if you plan on writing custom MembershipProviders, you need to follow the guidelines from Chapter 10 to ensure that your custom providers are thread-safe in all public properties and methods.

Although the Membership class is static, for historical reasons (the Membership feature was implemented very early on in the development cycle of ASP.NET 2.0) ...

Get Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB 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.