VS 2017- Adding Authentication: Individual User Accounts to an existing ASP.Net Core Web App

So you created your first asp.net core web app and did not select authentication. Now you realize you need it.

Here is the manual way to ” Install” Individual Accounts authentication

Load your existing project solution. Right Click dependencies and hit manage NuGet Packages.

Click the BROWSE button on the top left.

Here is where you will have to manually add the dependencies that your project is missing.

The list of NuGet packages to add is long and you may have to check Include PreRelease to see them all

  • Microsoft.AspNetCore.Authentication.Cookies
  • Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.SqlServer.Design
  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.Extensions.Configuration.UserSecrets
  • Microsoft.VisualStudio.Web.CodeGeneration.Design

Next, we are going to add the missing Controller files.

Add these three files to your Controllers Folder

AccountController.cs

ManageController.cs

HomeController.cs

Open all three of the files, and use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

This next step is to add the data that is missing.

Create a data folder and a subfolder of data called Migrations

Next, add this file to the Data folder

ApplicationDbContext.cs

Now add these three files to the Migrations folder

00000000000000_CreateIdentitySchema.cs

00000000000000_CreateIdentitySchema.Designer.cs

ApplicationDbContextModelSnapshot.cs

Now close any files you have open, saving each one.

Open the four files you just added.

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

Our nex step is to create all the missing models.

There is allot of them, So we are going to use zip and you will unzip them into your project directory

Models.Zip

Once your project is showing the models folder open every file in the models directory and subdirectories

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

Our next step is to add the missing Services

There is allot of them, So we are going to use zip and you will unzip them into your project directory

Services.zip

Once your project is showing the services folder open every file in the services directory

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

Next, we are going to add the missing view files.

There is allot of them, So we are going to use zip and you will unzip them into your project directory

This WILL NOT overwrite your HOME Views

Views.zip

Once your project is showing the views folder open every file in the views directory

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

The next step is to overwrite your Startup.cs file with the updates.

This is an overwrite operation, so if you have a none default startup.cs  file back it up so you can take your custom work and add it to the new file.

Startup.cs

Once your project is showing the views folder open every file in the views directory

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the files to your project.

Now the final step is to deal with the pesky SQL database connect string in appsettings.json

Overwrite your appsettings.json file with this one

appsettings.json

Once your project is showing the new appsetting.json file open it.

Use the Find and Replace feature under edit to find Logon and type in your project name in the replace with block. MAKE sure look in ALL open documents is selected and hit Replace all.

This will code the file to your project.

Save all files and Build it.

Troubleshooting:

  • If you updated any of your dependencies while in the NuGet Manager you will have to manually update your Core version by downloading the Current version HERE
  • If you have an orange triangle on any dependency under the NuGet packages, it just means you have to EXIT VS 17 and restart it.

I ran into both of these issues, but they are easy to overcome.

Hit your run with IIS button and enjoy seeing your new register and log on buttons on your old app.