[英]ASP.NET Identity: Custom stores
我正在嘗試使用N層體系結構以及自定義ASP.NET Identity服務和存儲庫創建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.
我嘗試找到任何解決方案,如何使用用戶的外鍵擴展登錄表(例如,如果您使用默認用戶存儲),但找不到任何解決方案。 任何想法?
謝謝您的幫助。
好吧,我通過自定義登錄類解決了。
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; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.