Add Identity as UI in ASP.NET Core 2.1 application

One of the new features of ASP.NET Core 2.1 is, Identity as UI library. Today, while working with Identity, you have to deal with thousands of lines of code and different files. But this new feature saves you from all the hassle of adding and configuring Identity to an ASP.NET Core application. In this post, find out how to add Identity as UI in ASP.NET Core 2.1 application.

Add Identity as UI in ASP.NET Core 2.1 application

Firstly, if you have still not installed .NET Core 2.1 preview, please do the following installation.

First thing first, open Visual Studio “Preview” version, hit Ctrl+Shift+N and select the ASP.NET Core Web Application (.NET Core) project type from the templates. When you click Ok, you will get the following prompt,

ASP.NET Core 2.1 Version Selector

As you can see, both the versions are listed in the drop-down. Select ASP.NET Core 2.1 and choose either Web Application or Web Application(MVC). The Web Application template will create an ASP.NET Core Razor pages based application. Hit Ok and let Visual Studio restores the packages. By default, in the ASP.NET Core 2.1 preview 1 version, the Identity is not added/configured. But adding Identity as UI is simple and straightforward. To add Identity as UI, follow the below given steps.

  • The Identity framework is available in a nuget package. So, you need to install the Microsoft.AspNetCore.Identity.UI nuget package.
    Install-Package Microsoft.AspNetCore.Identity.UI -Version 2.1.0-preview1-final
  • Next, we need to add only a single _ViewStart.cshtml file to the Areas->Pages->Identity folder in your project with the following code. These 3 folders are not present, so we need to create them.
        Layout = "/Pages/_Layout.cshtml";

    Now, the solution will look like,

    Adding Identity as UI in ASP.NET Core 2.1 application

  • Next, add the following code to configure Identity UI in Startup.cs -> ConfigureService() method.

    The AddDefaultUI() method does the trick here.

  • Lastly, add the Register and Login links to the homepage of the application. To do that, open _Layout.cshtml located under Pages directory and add the following code after the navigation bar code.

That’s it. Run the application and you should see the following.


The sample application and the source code is available at Github.


To conclude, the Identity as UI library is a time-saver feature which allows you to include the Identity framework with ease and without dealing with 50 different files and thousand lines of code. If you want to have more control on the default implementation, you can anytime use the new identity scaffolder to add the identity code in your app.

Thank you for reading. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.

PS: If you found this content valuable and want to return the favour, then Buy Me A Coffee

Leave a Reply

Your email address will not be published. Required fields are marked *