首页 > 解决方案 > 在 Visual Studio 上使用 Identity 创建新表和属性

问题描述

我正在尝试在默认身份表和我的默认身份表之间创建新表和关系,但是当我尝试使用 AccountController 上默认的“SignInManager.PasswordSignInAsync”方法登录时,我收到下面列出的错误:

我为创建身份上下文所做的是检查项目启动时的选项,然后在 AspNetUser 表上创建额外的属性,我这样做:

public class ApplicationUser : IdentityUser
{

    #region

    public DateTime LastLoginDateTime { get; set; }

    public string Name { get; set; }

    public string Surnames { get; set; }

    public string DNI { get; set; }

    public string ProfileImageSource { get; set; }

    #endregion


    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Tenga en cuenta que el valor de authenticationType debe coincidir con el definido en CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
        // Agregar aquí notificaciones personalizadas de usuario
        return userIdentity;
    }
}

然后我使用 Enable-Migrations 和 Update-Database。

直到这里一切正常,但是当我在同一个解决方案中使用另一个项目添加新表和关系(只是为了不混合我认为不好的上下文)与实体框架然后更新数据库时,我遇到了上面提到的问题。

注册新用户时工作正常,但是当调用“SignInManager.PasswordSignInAsync”方法时程序崩溃。

我不知道我在做什么错猜有人可以帮助我。

标签: c#.netasp.net-identityvisual-studio-2019web-application-project

解决方案


我刚刚解决了这个问题。

我不知道为什么,但是如果我在 SQL Server 中从 0 创建数据库,而不是 Visual Studio EDMX 编辑器,它就可以完美运行。

如果您想解决与我相同的问题,请直接在 SQL Server 上进行更改。


推荐阅读