Extend ASP .NET Identity with custom List<property> and access it in the View

天涯浪子 提交于 2019-12-12 04:57:46

问题


I am using ASP NET Identity 2.0. I need to extend the identity model with an ApplicationOrganization class (many-to-many with ApplicationUser).

So I created new class, ApplicationOrganization with;

public virtual ICollection<ApplicationUser> Users { get; set; }  
public virtual ICollection<ApplicationOrganization> Organizations { get; set;}         

to ApplicationUser class to create a many-to-many relationship.

I would like to add some combo (html select tag) with available organizations into _Layout.cshtml View. That's a problem for me. In the View I can accces current UserName, UserId or any other string property using Claims. But I don't know how to acces List of ApplicationOrganization connected to User in the View. I would like to avoid creating some new login Session. And I don't want to hit database in every view call.


回答1:


No answer. Ok, one way I know now is I can serialize list as a string (xml, json or whatever) and store it as Identity claim. When I need it I can parse it back.



来源:https://stackoverflow.com/questions/46050910/extend-asp-net-identity-with-custom-listproperty-and-access-it-in-the-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!