How to Store ASP.NET Core Identity Data in a JSON File

This article will show you how to store ASP.Net Core Identity data in a JSON file in just 8 Minutes. The guys at Microsoft decided to use the Entity Framework and an underlying database to store user information.

For small & development projects, that just does not feel right. What I prefer is a good old KISS solution (keep it simple stupid) or in other words a json file that has all the user data in it. Just to name a few advantages:

  • Easy to back up
  • Easy to analyze
  • Easy to modify

That is why I have developed the AspNetCore.Identity.FileSystem library. So here is how to use it:

First, create a new Web Application

Create a new Web Application

Then, for Authentication, use “Individual Accounts”

For Authentication use "Individual Accounts"

Next, you need to include the NuGet Package named AspNetCore.Identity.FileSystem

Then it is time to change the code like described here on the official project page.

So change this

by this

Generate the Identity Scaffolding

With asp.net core 2.1 the Identity Views are no longer generated but hidden in a class library. Thankfully, there is a way to generate these easily, as we do need them. Further information can be found here.

To generate the scaffolding, add a new scaffolding element to the project

and pick Identity

The Identity Views are now generated

Now the new Views can be found here

Eventually you have to delete the generated IdentityHostingStartup.cs class as this still refers to the Entity Framework

With this done, you can now start the App and should see something like that

You can now register as a user

And find the Identity data in File UserStore.json in the folder you passed before.

That’s it, plain and easy.

Find the project home page here on GitHub and the NuGet Package here on NuGet.