Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017:Access the change authentication screen on a already created Asp .Net Core Web Application

What if I wanted to add the Individual User Accounts to an existing Web application? How do I access this screen to upgrade my project without having to recreate the project? enter image description here

like image 701
Jeremiah Stillings Avatar asked Jan 04 '17 19:01

Jeremiah Stillings


People also ask

How do I change the authentication After creating a project?

Select File >> New >> select ASP.NET Core Web Application, and change the authentication to Windows Authentication. We can also configure the existing application for Windows Authentication by selecting the option of WA. To configure the authentication manually, open Visual Studio project properties >> go to Debug tab.

How do I change Windows Authentication in Visual Studio?

For . Start Visual Studio and select Create a new project. In the Create a new project dialog, select ASP.NET Core Web App (or Web API) > Next. In the Configure your new project dialog, enter Project name > Next. In the Additional Information dialog, select Authentication Type as Windows.


3 Answers

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.

enter image description here

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

They are found here

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. enter image description here

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 enter image description here

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

All found here

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. enter image description here

This will code the files to your project.

Our next 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. enter image description here

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. enter image description here

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. enter image description here

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. enter image description here

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. enter image description here

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. enter image description here

like image 172
Jeremiah Stillings Avatar answered Oct 25 '22 07:10

Jeremiah Stillings


The accepted answer may work, but there's a much easier way... (in my case, I'm changing from Windows authentication to Anonymous authentication).

  1. in Solution Explorer, select your project
  2. press F4 key to access Project Properties (note: beware, it's not the same as right-click project --> select Properties... use the F4 key)
  3. set Windows Authentication to Disabled
  4. set Anonymous Authentication to Enabled

  5. in the project's Web.config, in system.web section, change [authentication mode="Windows"] to [authentication mode="None"]
  6. in Web.config, in system.web section, change [deny users="?"] to [allow users="*"]


(sorry for the use of brackets, instead of actual tags - HTML post restrictions prevented using tags)

like image 26
jwdvorak Avatar answered Oct 25 '22 09:10

jwdvorak


No need to recreate a project, you can change this in your project properties:

enter image description here

like image 29
Antoine C. Avatar answered Oct 25 '22 08:10

Antoine C.