加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:04:08 所属栏目:百科 来源:网络整理
导读:我已经按照 http://www.asp.net/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity中的描述更改了PK,但是在我尝试登录后,我收到以下错误.登录部分成功,因为“this”包含所有相关数据,但创建身份似乎失败 从物化的“System.S
我已经按照 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读