2017-03-06 21 views
0

我想使用OWIN。但是我需要用戶表中更多的列。我也想用NHibernate使用自定義「用戶」表的ASP.NET身份

這樣做的方法是什麼? 從OWIN擴展用戶表。我不知道這是否可能。其次,我不知道我能否緩存問題。

或者,我爲我自己的用戶數據創建第二個用戶表,並將「UserID」屬性作爲引用OWIN的用戶表的外鍵?

+0

這正是Identity爲此設計的:可擴展性。如果你想要'ApplicationUser'上的額外屬性,只需添加它們。就像任何其他實體一樣。 Owin與身份或認證無關。身份恰好恰好是一個歐文中間件。 –

+0

okey。如果我有表沒有引用用戶表(和\t 相反),這是從ApplicationUser完全獨立的實體,我必須使用NHibernate獲取數據? – Xeddon

+0

@Xeddon根據標識和ApplicationUser處理的任何事情都由它自己的DbContext處理,如果您有其他與ApplicationUser無關的表由您自己的ORM處理,但是如果您希望在這些表中擁有UserId,您可以輕鬆地在NHibernate中將它們作爲外鍵映射到ApplicationUser表。 – Valkyrie

回答

0

反正我會說使用Asp.NET身份。如果你想爲你的ApplicationUser您可以添加它們像下面更多的屬性:

public class ApplicationUser : IdentityUser 
{ 
    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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; 
    } 

    // Your Extended Properties 
    public string FirstName{ get; set; } 
    public string LastName{ get; set; } 
    //... 
} 

你甚至可以創建User.Identity方法一樣容易地獲得屬性的值作爲GetUserId()方法。看看this

相關問題