Project maintained by lyphtec Hosted on GitHub Pages — Theme by mattgraham

SimpleMembership providers using MongoDB as the backing store

This this a SimpleMembership implementation using MongoDB as the backing store that provides a custom Membership provider (ExtendedMembershipProvider to be exact) and Role provider.

For more information about SimpleMembership see this post by Jon Galloway : SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates


Available on NuGet:

PM> Install-Package LyphTEC.MongoSimpleMembership

Required changes

You must complete the following steps after you have installed the NuGet package before your app will run:

  1. Configure your data connection string to the MongoDB database


        <add name="MongoSimpleMembership" connectionString="mongodb://localhost/SimpleMembership?safe=true"  />

    Note that the connection string must also include the database name. In the example above, this will use the database named "SimpleMembership".

  2. Update the system.web/membership & system.web/roleManager sections to use the connection string name as defined above

    Also make sure that the "defaultProvider" attributes are set to use the matching MongoSimpleMembership provider names.


      <membership defaultProvider="MongoSimpleMembershipProvider">
          <clear />
          <add name="MongoSimpleMembershipProvider" type="LyphTEC.MongoSimpleMembership.MongoSimpleMembershipProvider, LyphTEC.MongoSimpleMembership" connectionStringName="MongoSimpleMembership" />
      <roleManager enabled="true" defaultProvider="MongoRoleProvider">
          <clear />
          <add name="MongoRoleProvider" type="LyphTEC.MongoSimpleMembership.MongoRoleProvider, LyphTEC.MongoSimpleMembership" connectionStringName="MongoSimpleMembership" />
  3. If you are using the default "ASP.NET MVC4 Internet" template. You must make some changes to AccountController:

Customising the storage collection names

By default, the persisted entities are stored in collections with the following names:

Default collection names

This matches the table names used in the standard SQL Server based SimpleMembershipProvider.

If desired, you can change the default collection names by using the following appSettings:

    <add key="MongoSimpleMembership:MembershipAccountName" value="webpages_Membership" />
    <add key="MongoSimpleMembership:OAuthMembershipName" value="webpages_OAuthMembership" />
    <add key="MongoSimpleMembership:OAuthTokenName" value="webpages_OAuthToken" />
    <add key="MongoSimpleMembership:RoleName" value="webpages_Role" />


Apache License, Version 2.0


blog comments powered by Disqus