身份2与身份.NET共存6-锁定限制错误

发布于 2025-02-13 22:40:25 字数 1131 浏览 3 评论 0 原文

我们将客户端的Web应用程序从.NET 4.6升级到.NET 6。旧系统使用身份2和EF 6。这两个系统都需要在不确定的时间内共存。 首先,如果不覆盖旧系统中的密码,我们无法从新系统中登录,从而使其无法使用。我们用:

services.Configure<PasswordHasherOptions>(option => option.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);

然后遵循概述此stackoverflow文章有脚本可以更新sql表并告诉我们如何包括 Microsoft.aspnet.Identity.CoreCompat 库。但是,在 lockoutend 字段中, aspnetusers 表中似乎不起作用。脚本将此字段作为DateTime2字段留下。但是,在.NET 6中运行时,我们会收到错误:

System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.DateTimeOffset'.

将SQL中的字段更改为DateTimeOffset(7)允许Identity .NET 6工作,但是打破身份2,因为它期望类型DateTime并获得DateTimeOffset。 如果字段为null,则没有问题。但是,如果该领域有日期,则任何访问用户的东西,例如 FindbyNameSync 都会丢弃错误。

必须是一种工作的方法。我无法想象我们是唯一遇到这个问题的人。我不知道其他所有人会如何滑倒。

有人对此有解决方案吗?我是否缺少其他配置设置?

We are upgrading a client's web app from .NET 4.6 to .Net 6. The old system uses Identity 2 and EF 6. Both systems need to coexist for an indefinite period of time.
At first we could not log in from the new system without it overwriting the passwords in the old system, making them unusable. We fixed that with:

services.Configure<PasswordHasherOptions>(option => option.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV2);

Then we followed the path outlined this StackOverflow article which had scripts to update the SQL tables and tells us how to include the Microsoft.AspNet.Identity.CoreCompat library. However, it seems to not work when it comes to the LockoutEnd field in the AspNetUsers table. The scripts leave this field as a datetime2 field. However, when running in .NET 6, we get the error:

System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.DateTimeOffset'.

Changing the field in SQL to a DateTimeOffset(7) allows Identity .NET 6 to work, but breaks Identity 2 because it expects type DateTime and got DateTimeOffset.
If the field is null, it works no problem. However, if there was a date in the field, anything accessing the user, like FindByNameAsync will throw the error.

There must be a way for this to work. I can't imagine we are the only ones having this problem. I have no idea how this could have slipped by everyone else.

Does anyone have a solution to this? Is there some other config setting I am missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文