使用自定义List< property>扩展ASP .NET Identity.并在视图中访问它 [英] Extend ASP .NET Identity with custom List<property> and access it in the View
问题描述
我正在使用ASP NET Identity 2.0.我需要使用ApplicationOrganization类(与ApplicationUser一对多)来扩展身份模型.
I am using ASP NET Identity 2.0. I need to extend the identity model with an ApplicationOrganization class (many-to-many with ApplicationUser).
所以我创建了新类ApplicationOrganization with;
So I created new class, ApplicationOrganization with;
public virtual ICollection<ApplicationUser> Users { get; set; }
public virtual ICollection<ApplicationOrganization> Organizations { get; set;}
到ApplicationUser类以创建多对多关系.
to ApplicationUser class to create a many-to-many relationship.
我想在_Layout.cshtml视图中添加一些带有可用组织的组合(html选择标记).这对我来说是个问题.在视图中,我可以使用Claims来访问当前的UserName,UserId或任何其他字符串属性.但是我不知道如何在视图中访问连接到用户的ApplicationOrganization列表.我想避免创建一些新的登录会话.而且我不想在每个视图调用中都访问数据库.
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.
推荐答案
没有答案.好的,我现在知道的一种方法是,我可以将列表序列化为字符串(xml,json或其他)并将其存储为Identity声明.当我需要它时,我可以将其解析回去.
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.
这篇关于使用自定义List< property>扩展ASP .NET Identity.并在视图中访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!