2 回答

TA贡献1829条经验 获得超7个赞
因此,为了回答您的问题,该Parse
方法使用当前语言环境将您的字符串转换为整数。我猜在您的情况下,这GetUserID()
将采用您当前语言环境期望逗号作为小数点的格式。因此,提供可选参数CultureInfo.InvariantCulture
将使您的区域设置文化不敏感。另一种方法是提供第二个可选参数来提供IFormatProvider。
要解决您的错误,请将此行设置为:
(id)=>Int32.Parse(id.GetUserId(),CultureInfo.InvariantCulture)
有关CultureInfo.InvariantCulture的更多信息。

TA贡献1826条经验 获得超6个赞
回答我的问题。
在我的 startup.auth.cs
如前所述,我遵循了所有 microsoft 文档。
运行项目时,我不断收到错误消息。
在 CookieAuth 下的 ConfigureAuth() 中添加 CultureInfo 作为第二个参数。
这是我完成的项目代码。
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator
.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>
(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentityCallback: (manager, user) =>
user.GenerateUserIdentityAsync(manager),
getUserIdCallback:(id) => Int32.Parse(id.GetUserId(),
CultureInfo.InvariantCulture)
//getUserIdCallback:(id) => (Int32.Parse(id.GetUserId()))
)
}
- 2 回答
- 0 关注
- 149 浏览
添加回答
举报