微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐