问题描述
我相信 .NET Identity 3 不能在现有 (v4.5) ASP.NET 解决方案上运行,但需要 .NET Core.我无法更新到 .NET Core.有解决方法吗?如果不是,那么人们应该如何从 ASP.NET Membership 迁移到 ASP.Net Identity?
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?
推荐答案
首先,我需要注意 ASP.NET Core(适用于 Identity 3)不需要 .NET Core.它可以在 .NET Core 或 .NET Framework 4.6.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).
当有关用户、角色、密码等的所有信息都存储在某个数据库中时,我猜您在这两种情况下(成员身份和身份)都使用默认方法.
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.
因此,从 Membership 迁移到 Identity 的最佳方法如下:
So, the best way to migrate from Membership to Identity is the following:
- 使用默认模板创建一个新的 ASP.NET Core 项目并启用身份验证"
- 然后编写一个小的控制台程序,它将所有与用户相关的信息从旧的成员资格表移动到新的成员资格表(由 ASP.NET Identity 自动创建)
- 然后一一移动所有其他控制器和视图.
这里唯一的问题是 Identity 无法识别使用 Membership 创建的密码哈希.要解决此问题,您需要定义自己的 IPasswordHasher 接口实现并将其注册到 DI 容器中,如 这篇文章.
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.
这篇关于现有解决方案上的 .Net Identity 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!