.Net Identity 3 on existing solution

2019-08-19 06:11发布

问题:

I believe that .NET Identity 3 cannot run on an existing (v4.5) ASP.NET solution, but requires .NET Core. I cannot update to .NET Core. Is there a workaround for this? If not then how are people supposed to migrate from ASP.NET Membership to ASP.Net Identity?

回答1:

  1. First of all, I need to note that ASP.NET Core (which works with Identity 3) does not require .NET Core. It can be used either over .NET Core or .NET Framework 4.6.1 (or higher).

  2. I guess you use the default approach in both cases (Membership and Identity) when all information about users, roles, passwords, etc, is stored in some database.

So, the best way to migrate from Membership to Identity is the following:

  • create a new ASP.NET Core project using the default template and with "Authentication" turned on
  • then write a small console program which will move all user-related information from your old membership tables to the new ones (created automatically by ASP.NET Identity)
  • then move all other your controllers and views one by one.

The only problem here - is that Identity will not recognize the passwords' hashes created with Membership. To resolve it you will need to define your own implementation of IPasswordHasher interface and register it in DI container as it's described in this article.