Click here to Skip to main content
Click here to Skip to main content
Go to top

BetterMembership.Net v1.0

, 3 Oct 2013
Rate this:
Please Sign up or sign in to vote.
A better implementation of ExtendedMembershipProvider with support for legacy MembershipProvider APIs.

Introduction

In a previous article entitled SimpleMembershipProvider vs MembershipProvider I described the limitations in using SimpleMembershipProvider as a MembershipProvider. This is a followup article which provides my own solution to this problem.

The BetterMembership.Net library bridges the gap between the ExtendedMembershipProvider interface which is used with the WebSecurity API via SimpleMembershipProvider (see ASP.NET MVC4 Web Application - Internet template), and the older MembershipProvider interface (see ASP.NET Web Forms template).

By using the BetterMembership.Net library you can take advantage of the newer features of ExtendedMembershipProvider, but still use pre-existing user management tools for out-of-box user administration (including ASP.NET Web Site Administration Tool). This is not possible when using the vanilla SimpleMembershipProvider implementation of ExtendedMembershipProvider.

Features

  • Supports SQL Server, SQL Compact and SQL Azure
  • Compatible with EntityFramework and code-first
  • Uses a clean database schema
  • Works with existing user tables
  • Plugs into existing user administration tools (including WSAT)
  • Supports initialization of multiple provider instances
  • Supports external authentication providers
  • Provides customizable validation of username/email/password

How It Works

The library overcomes limitations of the WebSecurity implementation, and allows multiple provider instances to be configured and used at runtime. This is useful for complex applications that involve multiple authentication schemes for partitioning users, such as in Sitecore for example.

The achieve this, the library uses a bit of reflection to swap out the default provider at runtime during a call to WebSecurity.InitializeDatabaseConnection. This overcomes the limitations hardwired into the WebSecurity implementation, and enables multiple provider instances to be initialized (rather than only the default instance). Of course these can't then be used with WebSecurity API directly, but can be used effectively with dependency injection.

The call to WebSecurity.InitializeDatabaseConnection now actually happens inside the provider's own Initialize method to make the provider entirely self-contained and backwards compatible. This feature can be disabled for use with code-first, but it does enable users to be administrated via the Visual Studio WSAT tool or by other provider based interfaces. 

Under the hood the library extends SimpleMembershipProvider and implements many of the unsupported methods. To facilitate this it introduces a new userEmailColumn property on the provider, and uses this to map the user defined email column to the email property of the MembershipUser instance returned by the older APIs. Likewise other properties are mapped to the new schema, and default values returned for any unsupported members.

Extended Implementation

The following methods missing from SimpleMembershipProvider are implemented by BetterMembershipProvider.

  • CreateUser
  • GetUser+
  • GetUserNameByEmail
  • FindUserByUserName
  • FindUserByEmail
  • GetAllUsers
  • FindUsersByName
  • FindUsersByEmail
  • UnlockUser
  • ResetPassword

+ The userIsOnline flag is ignored, but may be implemented in the future.

Installation

Install the library using Nuget.

PM> Install-Package BetterMembership.Net

Documentation & Source

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

TheCodeKing
Architect
United Kingdom United Kingdom
Mike Carlisle - Technical Architect with over 15 years experience in a wide range of technologies.
 
@TheCodeKing
Follow on   Twitter

Comments and Discussions

 
QuestionDoes website timeout work with your version? PinmemberDaveKolb2-Nov-13 4:55 
AnswerRe: Does website timeout work with your version? PinmemberTheCodeKing4-Nov-13 11:46 
GeneralRe: Does website timeout work with your version? PinmemberDaveKolb4-Nov-13 15:52 
Questionsupport for dynamic connection string? PinmemberMikeMardon29-Oct-13 23:55 
AnswerRe: support for dynamic connection string? PinmemberTheCodeKing30-Oct-13 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 3 Oct 2013
Article Copyright 2013 by TheCodeKing
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid