c# – ASP.NET Identity 2.1将PK更改为int错误

我已经按照 http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity中的描述更改了PK,但是在我尝试登录后,我收到以下错误.登录部分成功,因为“this”包含所有相关数据,但创建身份似乎失败

从物化的“System.String”类型到“system.int32”类型的指定强制转换无效.

在线

var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);

方法

public class ApplicationUser : IdentityUser<int,CustomUserLogin,CustomUserRole,CustomUserClaim>
{
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser,int> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationoptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
        // Add custom user claims here
        return userIdentity;
    }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}

解决方法

我也有同样的问题..唯一的区别是我的错误是在AddToRole或AddToRoleAsync期间.

The specified cast from a materialized ‘System.String’ type to the ‘system.int32’ type is not valid.

违规行位于:await UserManager.AddToRoleAsync(user.Id,model.RoleId);

事实证明,我需要更改表AspNetRoles的密钥……也许这张图片更清晰..

enter image description here

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...