Adding Identity to an existing project

2019-06-20 01:20发布

问题:

I've got an MVC project, and I want to add Identity to it, but I can't seem to find any good articles on how to do so.

Is there an easy way to add Identity to an existing project?

I already have a database with stuff in it

回答1:

Well, in one respect, you simply have to add the Nuget package and start writing code with it, but I think you're probably talking about all the extras: the pre-written code and samples for doing things like password resets, two-factor auth, etc.

For that, no, there's not really an easy way, at least in the sense of click a button and go. What I would recommend is creating a new MVC 5 project with Individual Auth, and then adding the Identity Samples Nuget package to it. Then, open your existing project in another Visual Studio window and copy/paste or use the sample code as a guide for writing your own.



回答2:

Here's a tutorial that I followed for adding ASP.Net Identity to an existing project. It's up to date and from a reputed source at the asp.net/identity site.



回答3:

I will echo what Chris said. there is no "easy way" . here is a video link featuring Scott Allen (a pioneer in web dev (Video link)

You can check his other videos as well



回答4:

I think the easiest way to do that is to do the following steps:

  • Install All Identity Packages from nugets to your existing MVC project.

  • Create New MVC Project and choose Authentication type: Individual Authentication.

  • Copy IdentityModels.cs and all related files including (controllers, views and IdentityConfig) from New project to an existing MVC project.

  • Add migration to create required tables on database.