Creating an ASP.NET Core application that supports identity used to be tedious … not anymore!
Using Visual Studio 2017, you can create identity support for your ASP.NET MVC application using the built-in MVC Razor Identity scaffolding wizard.
The built-in identity scaffold provides the following features:
2 Factor Authentication
User Account Management
Account Lockout User Registration
To do this, you just go to the project, right click and create a new scaffolded item …
Select the identity scaffolder, then add.
In the next screen, select all the files to override.
Wait a few minutes and the source and content files for identity will be created in the folder
Areas / Identity / Pages / Account
and Areas / Identity / Pages / Account / Manage
Before you can see the Login and Register menu links, you will need to do the following.
Open the shared layout view file in \Pages\Shared\_layout.cshtml.
Go to the source block showing the following:
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse"> <ul class="navbar-nav flex-grow-1"> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a> </li> </ul> </div>
Then just after the above, insert/type in the following source to expose the login partial view:
Save the layout view.
Build the application.
When the application is run, the following menus will appear in the top right corner of the web form:
The login menu when clicked will show a functional login screen …
Click on the register menu and a functional user registration screen will show …
Hope this has been useful for anyone either starting out with ASP.NET Core MVC or doesn’t have the time to develop a fully functional identity management system.
In a later post I will discuss other identity management frameworks that can be used within ASP.NET Core. Stay tuned!
Andrew Halil is a blogger, author and software developer with expertise of many areas in the information technology industry including full-stack web and native cloud based development, test driven development and Devops.