Rammi.MongoDb.AspNet.Identity 2.0.5

dotnet add package Rammi.MongoDb.AspNet.Identity --version 2.0.5
                    
NuGet\Install-Package Rammi.MongoDb.AspNet.Identity -Version 2.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rammi.MongoDb.AspNet.Identity" Version="2.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rammi.MongoDb.AspNet.Identity" Version="2.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Rammi.MongoDb.AspNet.Identity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rammi.MongoDb.AspNet.Identity --version 2.0.5
                    
#r "nuget: Rammi.MongoDb.AspNet.Identity, 2.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rammi.MongoDb.AspNet.Identity@2.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rammi.MongoDb.AspNet.Identity&version=2.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Rammi.MongoDb.AspNet.Identity&version=2.0.5
                    
Install as a Cake Tool

Rammi.MongoDb.AspNet.Identity

ASP.NET Identity provider that uses MongoDB for storage

Recent Updates (2025)

This project has been updated to:

  • Namespace: Changed to Rammi.MongoDb.AspNet.Identity
  • NuGet Package: Rammi.MongoDb.AspNet.Identity (version 2.0.3)
  • Target Framework: .NET Framework 4.8
  • MongoDB Driver: Updated to MongoDB.Driver 3.5.1 and MongoDB.Driver.Core 2.30.0
  • Dependencies: Updated Microsoft.AspNet.Identity.Core to version 2.2.4
  • Maintained by: Rammi (https://rammi.cz)

Purpose

ASP.NET MVC 5 shipped with a new Identity system (in the Microsoft.AspNet.Identity.Core package) in order to support both local login and remote logins via OpenID/OAuth, but only ships with an Entity Framework provider (Microsoft.AspNet.Identity.EntityFramework).

News

02-11-2014 - [http://blogs.msdn.com/b/webdev/archive/2014/02/11/announcing-preview-of-microsoft-aspnet-identity-2-0-0-beta1.aspx](Microsoft has released Microsoft.AspNet.Identity v2 Beta 1). I will be addressing these issues and introducing them into the MongoDB.AspNet.Identity provider.

Features

  • Drop-in replacement ASP.NET Identity with MongoDB as the backing store.
  • Requires only 1 mongo document type, while EntityFramework requires 5 tables
  • Contains the same IdentityUser class used by the EntityFramework provider in the MVC 5 project template.
  • Supports additional profile properties on your application's user model.
  • Provides UserStore<TUser> implementation that implements the same interfaces as the EntityFramework version:
    • IUserStore<TUser>
    • IUserLoginStore<TUser>
    • IUserRoleStore<TUser>
    • IUserClaimStore<TUser>
    • IUserPasswordStore<TUser>
    • IUserSecurityStampStore<TUser>
    • IUserEmailStore<TUser> (1.0.7)
    • IUserLockoutStore<TUser, string> (1.0.7)
    • IUserTwoFactorStore<TUser, string> (1.0.7)

Instructions

These instructions assume you know how to set up MongoDB within an MVC application.

  1. Create a new ASP.NET MVC 5 project, choosing the Individual User Accounts authentication type.
  2. Remove the Entity Framework packages and replace with MongoDB Identity:
Uninstall-Package Microsoft.AspNet.Identity.EntityFramework
Uninstall-Package EntityFramework
Install-Package Rammi.MongoDb.AspNet.Identity
  1. In ~/Models/IdentityModels.cs:
    • Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
    • Add the namespace: Rammi.MongoDb.AspNet.Identity
    • Remove the ApplicationDbContext class completely.
  2. In ~/Controllers/AccountController.cs
    • Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
    • Add the connection string name to the constructor of the UserStore. Or empty constructor will use DefaultConnection
  3. In ~/App_Start/IdentityConfig.cs
    • Remove reference to ApplicationDbContext
    • Amend ApplicationUserManager to inherit UserManager<ApplicationUser, string>. Also amend parameter for ApplicationUser.GenerateUserIdentityAsync
  4. In ~/App_Start/Startup.Auth.cs
    • Remove app.CreatePerOwinContext<ApplicationDbContext>(ApplicationDbContext.Create);
AccountController requires a parameterless constructor. 
You could instantiate the UserManager in this contructor using any the UserStore constructors.
public AccountController()
{
    //examples
    this.UserManager = 
    new ApplicationUserManager(new UserStore<ApplicationUser>("MyConnection"));
}

Connection Strings

The UserStore has multiple constructors for handling connection strings. Here are some examples of the expected inputs and where the connection string should be located.

1. SQL Style

UserStore<TUser>(string connectionNameOrUrl)

<code>UserStore<TUser>("Mongo")</code>

web.config

<add name="Mongo" connectionString="Server=localhost:27017;Database={YourDataBase}" />

2. Mongo Style

UserStore<TUser>(string connectionNameOrUrl)

<code>UserStore<TUser>("Mongo")</code>

web.config

<add name="Mongo" connectionString="mongodb://localhost/{YourDataBase}" />

OR

UserStore<TUser>(string connectionNameOrUrl)

<code>UserStore<TUser>("mongodb://localhost/{YourDataBase}")</code>

Thanks To

Special thanks to David Boike whos RavenDB AspNet Identity project gave me the base for jumpstarting the MongoDB provider

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5 241 12/3/2025
2.0.4 689 12/3/2025
2.0.3 689 12/3/2025

Version 2.0.5
- Added public Collection property to UserStore for custom queries (e.g. counting users)

Version 2.0.4
- Updated to MongoDB.Driver 3.5.2

Version 2.0.3
- Changed namespace to Rammi
- Renamed package to Rammi.MongoDb.AspNet.Identity (removed Core from name)
- Targeting .NET Framework 4.8 exclusively

Version 2.0.2
- Updated to MongoDB.Driver 3.5.1 and MongoDB.Driver.Core 2.30.0
- Updated Microsoft.AspNet.Identity.Core to 2.2.4
- Updated dependencies