【问题标题】:ASP.NET Identity: Custom storesASP.NET 标识:自定义商店
【发布时间】:2015-01-28 13:38:50
【问题描述】:

我正在尝试使用 N 层架构和自定义 ASP.NET 身份服务和存储库创建 ASP.NET MVC 项目。我已经实现了自定义 UserStore

UserStore: UserIUserStore<User>, IUserPasswordStore<User>, IUserRoleStore<User>, IUserLoginStore<User>, IUserEmailStore<User> 

我已经实现了注册和登录。现在我想通过社交网络实现登录,但我卡住了。

public class User : IUser<string>
{
    [Required]
    public string Id { get; set; }

    [Required]
    public string UserName { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    public string Email { get; set; }

    [Required]
    public string PasswordHash { get; set; }

    public virtual ICollection<Role> Roles { get; set; }

    public virtual ICollection<UserLoginInfo> Logins { get; set; }
}

UserLoginInfo 是 IUserLoginStore 中用于登录信息的 sealead 类。但是,如果我想添加迁移,则会收到此错误:

NtierMVC.Repositories.UserLoginInfo: : EntityType 'UserLoginInfo' has no key defined. Define the key for this EntityType.
Login: EntityType: EntitySet 'Login' is based on type 'UserLoginInfo' that has no keys defined.

我试图找到任何解决方案,如何使用外键将登录表扩展给用户(例如,如果您使用默认用户存储),但没有找到。有什么想法吗?

感谢您的帮助。

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-identity


    【解决方案1】:

    好吧,我用自定义登录类解决了。

    public class ExternalLogin
    {
        public string UserId { get; set; }
    
        [Key, Column(Order = 0)]
        public string LoginProvider { get; set; }
    
        [Key, Column(Order = 1)]
        public string ProviderKey { get; set; }
    
        public UserLoginInfo GetUserLoginInfo()
        {
            return new UserLoginInfo(LoginProvider, ProviderKey);
        }
    }
    
     public class User : IUser<string>
     {
        // user properties
    
        public virtual ICollection<ExternalLogin> Logins { get; set; }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多