AspNetCore.Identity.Stores.AzureCosmosDB 2.0.0

.NET 6.0
NuGet\Install-Package AspNetCore.Identity.Stores.AzureCosmosDB -Version 2.0.0
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.
dotnet add package AspNetCore.Identity.Stores.AzureCosmosDB --version 2.0.0
<PackageReference Include="AspNetCore.Identity.Stores.AzureCosmosDB" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.Identity.Stores.AzureCosmosDB --version 2.0.0
#r "nuget: AspNetCore.Identity.Stores.AzureCosmosDB, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspNetCore.Identity.Stores.AzureCosmosDB as a Cake Addin
#addin nuget:?package=AspNetCore.Identity.Stores.AzureCosmosDB&version=2.0.0

// Install AspNetCore.Identity.Stores.AzureCosmosDB as a Cake Tool
#tool nuget:?package=AspNetCore.Identity.Stores.AzureCosmosDB&version=2.0.0

Azure Cosmos DB

This is how to use Azure Cosmos DB as storage for ASP.NET identity.

  1. Create a new ASP.NET Core Web App

  2. From Additional information dialog select authentication type Individual Accounts

  3. Install AspNetCore.Identity.Stores.AzureCosmosDB package from NuGet manager

    <code>Install-Package AspNetCore.Identity.Stores.AzureCosmosDB</code>

  4. In Program.cs replace DbContext and Identity initialization with the folowing code

    using AspNetCore.Identity.Stores;
    using AspNetCore.Identity.Stores.AzureCosmosDB.Extensions;
    var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
    //Configure identity repository connection
    builder.Services.Configure<IdentityStoresOptions>(options => options
                    .UseAzureCosmosDB(connectionString, databaseId: "MyDatabase"));
    builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
                    .AddAzureCosmosDbStores(); //Add Identity stores
  5. In appsettings.json update DefaultConnection with Azure Cosmos DB connection string.


As shown in the code snippet from point 4, IdentityStoresOptions has an extension method UseAzureCosmosDB to configure the connection and it has 3 parameters:

  • connectionString: To specify the connection string of CosmosDB instance.
  • databaseId: To specify the database which will be used.
  • containerId (optinal): To specify the container which will be used, the default value is AspNetIdentity

Note: If the specified database or container not exist, they will get created on startup.

See more:

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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.0 102 8/14/2022
1.1.0 421 5/17/2022
1.0.3 643 9/17/2021
1.0.2 159 9/2/2021
1.0.1 146 8/19/2021
1.0.0 190 8/1/2021