输入字符串的格式不正确 - 使用了错误的上下文

Jey*_*eyJ 5 .net c# asp.net-core

将 ASP.NET Core Identity 更改为使用int而不是 GUID(根据此博客文章)后,我收到以下错误:

ArgumentException: 395438ed-1cd9-4420-8a58-3f3b1f550bfc 不是 Int32 的有效值。参数名称:值 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(string id) Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore.FindByIdAsync(string userId, CancellationToken) cancelToken) Microsoft.AspNetCore.Identity.UserManager.FindByIdAsync(string userId) Microsoft.AspNetCore.Identity.UserManager.GetUserAsync(ClaimsPrincipal principal) Microsoft.AspNetCore.Identity.SignInManager.ValidateSecurityStampAsync(ClaimsPrincipalPrincipal) Microsoft.AspNetCore.Identity.SecurityStampValidAsyncator (CookieValidatePrincipalContext 上下文)Microsoft.AspNetCore.Authentication。

尝试查询数据库时。关于为什么会这样的任何线索?

mjw*_*lls 7

根据博客文章中的评论之一:

谢谢,这篇文章真的很有用。对我来说一个问题是,当我第一次再次加载身份服务器时切换到使用 int 后,我​​在这条线上遇到了错误

Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(string id)。

原来我有一个使用旧 guid 格式的 cookie,简单的解决方法是清除 cookie。

问题是您之前的某些登录可能是在 ID 是 GUID 时完成的。您将其更改为int,因此现在它不再知道如何处理 GUID。最简单的解决方案是删除您的 cookie,有效地将您注销并强制您再次登录(int改为使用)。