输入字符串的格式不正确-使用了错误的上下文 [英] Input string was not in a correct format - wrong context is used

查看:136
本文介绍了输入字符串的格式不正确-使用了错误的上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将ASP.NET Core身份更改为使用int而不是GUID之后(按照

After changing ASP.NET Core Identity to use int rather than GUID (as per this blog post) I am receiving the following error:

ArgumentException:395438ed-1cd9-4420-8a58-3f3b1f550bfc无效 Int32的值.参数名称:值 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext 上下文,CultureInfo文化,对象值) Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(字符串ID) Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore.FindByIdAsync(string userId,CancellationToken cancelToken) Microsoft.AspNetCore.Identity.UserManager.FindByIdAsync(string 用户身份) Microsoft.AspNetCore.Identity.UserManager.GetUserAsync(ClaimsPrincipal 主要的) Microsoft.AspNetCore.Identity.SignInManager.ValidateSecurityStampAsync(ClaimsPrincipal 主要的) Microsoft.AspNetCore.Identity.SecurityStampValidator.ValidateAsync(CookieValidatePrincipalContext 语境) Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationHandler.AuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext 上下文,字符串方案) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext 语境) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext 语境) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext 上下文)

ArgumentException: 395438ed-1cd9-4420-8a58-3f3b1f550bfc is not a valid value for Int32. Parameter name: value 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 cancellationToken) Microsoft.AspNetCore.Identity.UserManager.FindByIdAsync(string userId) Microsoft.AspNetCore.Identity.UserManager.GetUserAsync(ClaimsPrincipal principal) Microsoft.AspNetCore.Identity.SignInManager.ValidateSecurityStampAsync(ClaimsPrincipal principal) Microsoft.AspNetCore.Identity.SecurityStampValidator.ValidateAsync(CookieValidatePrincipalContext context) Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler.HandleAuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationHandler.AuthenticateAsync() Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

在尝试查询数据库时.关于这可能是什么的任何线索?

when trying to query the database. Any clues as to why that might be?

推荐答案

根据

谢谢,这篇文章真的很有用.对我来说一个陷阱是 当我再次加载身份服务器时,交换使用int后 我在这条线上出现错误

Thank you, this article was really useful. One gotcha for me was that after swapping to use an int when I first loaded identity server again I got an error on this line

Microsoft.AspNetCore.Identity.UserStoreBase.ConvertIdFromString(字符串ID).

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

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

Turns out I had a cookie using the old guid format, simple fix was to clear cookies.

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

The issue is that some of your previous logins were likely done when the ID was a GUID. You changed it to int, and so now it doesn't know how to handle the GUID any more. The simplest solution will be to delete your cookies, effectively logging you out and forcing you to login again (using int instead).

这篇关于输入字符串的格式不正确-使用了错误的上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆