Reputation: 761
I am following a course on ASP.Net MVC and reached a point where the course relies on the standard "Register" and "Log In" functions that Visual Studio automatically builds when you select "Individual User Accounts" when creating the proj.
Apparently, newer versions of Visual Studio now default to "No Authentication".
I've built a lot of stuff and it would be a pain to create a new project and move everything over. Is there an easier way of changing the authentication type (and generating the respective pages and controllers)?
(I don't want to add identity and tweak the authentication process manually, I want to have the same result as if I was creating a new project with "Individual User Accounts" set - with VS creating default controllers and views)
Upvotes: 16
Views: 24178
Reputation: 29
someone in the C# discord community gave me a quick solution to this .
5.resource
Upvotes: 0
Reputation: 761
Inserted a point you missed after 6th step. Also thanks for the solution !
Found a solution!
Create a new dummy project of the same type, but with the "Individual User Accounts" authentication type selected. This will generate the files you need.
On the current project (with "No Authentication"), use the Package Manager Console to add the following references (the ones you don't have yet):
After adding these files to the solution, change their namespaces according to live project (replace all).
Open "IdentityModels.cs" and change the ConnectionString in "ApplicationDbContext" to match your live one (as in Web.config)
Open your \Views\Shared_Layout.cshtml file and add
@Html.Partial(“_LoginPartial”)
7) Copy the ... from Web.config of Dummy project to the main project.(You missed this point which might result in issues like database not being created)
Upvotes: 34
Reputation: 941
You would need to install Identity using nuget into your project. Here is a good StackOverflow thread that you can follow -
Adding ASP.NET MVC5 Identity Authentication to an existing project
Upvotes: 2