Click here to Skip to main content
12,883,390 members (41,544 online)
Click here to Skip to main content
Add your own
alternative version


14 bookmarked
Posted 3 Oct 2013

BetterMembership.Net v1.0

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


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.


  • 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.


Install the library using Nuget.

PM> Install-Package BetterMembership.Net

Documentation & Source


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


About the Author

United Kingdom United Kingdom
Mike Carlisle - Technical Architect with over 20 years experience in a wide range of technologies.


You may also be interested in...

Comments and Discussions

QuestionCall it ConfusedMembership.. not necessarily better. Pin
freddie200031-Jul-15 3:13
memberfreddie200031-Jul-15 3:13 
QuestionDoes website timeout work with your version? Pin
DaveKolb2-Nov-13 4:55
memberDaveKolb2-Nov-13 4:55 
AnswerRe: Does website timeout work with your version? Pin
TheCodeKing4-Nov-13 11:46
memberTheCodeKing4-Nov-13 11:46 
GeneralRe: Does website timeout work with your version? Pin
DaveKolb4-Nov-13 15:52
memberDaveKolb4-Nov-13 15:52 
Questionsupport for dynamic connection string? Pin
MikeMardon29-Oct-13 23:55
memberMikeMardon29-Oct-13 23:55 
AnswerRe: support for dynamic connection string? Pin
TheCodeKing30-Oct-13 9:05
memberTheCodeKing30-Oct-13 9:05 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170422.1 | Last Updated 3 Oct 2013
Article Copyright 2013 by TheCodeKing
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid