创建 ASP.Net 角色表的外键
我有一个 Pages 表,我有一个 PagesRoles 表,其中包含链接到 ASP.Net 成员角色表和 Pages 表的 PageId、RoleID。
我想以某种方式返回链接到当前登录的用户角色的页面。
用户可能担任多个角色。 一个页面可以有多个针对它的角色。
我有一个 Page 类,其外键属性为 IQueryable。 PageRoles 有一个 IQueryable 到 ASPNet 角色表 (IQueryable) 和 IQueryable
谢谢
编辑:
使用 Adam 的答案来获取分配有与当前登录用户的角色之一匹配的角色的所有页面,我有一个添加的问题。 我有一个菜单表,其中有一个 PageID 外键和一个 CategoryID。
我想返回 CategoryID 为 4 的所有菜单项。对于那些具有 PageID 的菜单项,我需要确保允许用户根据其角色查看该页面。 我认为亚当的查询可以做到这一点。 所以我认为我需要的是一个 UNION,返回所有 PageID 为 null 且 CategoryID 为 4 的菜单项,并返回所有 CategoryID 为 4 的菜单项,并加入到当前用户角色所在的 Page->PageRole->ASPNetRole ASPNetRole 结果。
I have a Pages table, I have a PagesRoles table with PageId, RoleID that links to ASP.Net Membership Roles table and the Pages table.
I want to somehow return a Page that links to the currently logged in User's Roles.
The User may be in more than one role. A Page can have more than one Role against it.
I have a Page class that has a foreign key property of IQueryable. PageRoles has a IQueryable to ASPNet Roles table (IQueryable) and IQueryable
Thanks
EDIT:
Using Adam's answer to get all Pages that have a role assigned to it which matches one of the currently logged in user's roles I have a added issue. I have a Menu table that has a PageID foreign key and a CategoryID.
I would like to return all Menu items with a CategoryID of 4. For those that have a PageID I need to make sure that the user is allowed to see that Page based on his role. I think Adam's query would do that. So I think what I need is a UNION, return all Menu items where PageID is null and CategoryID is 4 and return all Menu items where CategoryID is 4 and join to the Page->PageRole->ASPNetRole where current users roles is in that ASPNetRole results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 SubSonic 3,类似以下的查询应该有效:
If you're using SubSonic 3 a query like the following should work: