扩展 RoleProvider GetRolesForUser()
RoleProvider
中的 GetRolesForUser()
方法获取用户登录名并返回该用户的角色列表。但在我的应用程序中,这还不够,我需要更多信息才能获取用户的角色。
我怎样才能将这些额外的信息添加到方法中?
我在 Session
中有它,但我发现 Session
在 RoleProvider
中不可用。
我的想法是将这些额外的信息放在扩展 MembershipUser
的某个类中,假设我可以在 RoleProvider
中访问它。但我不知道如何创建 CustomMembershipUser
并使其成为 MembershipProvider
的一部分。这可能吗?
最简单的方法是使用cookie,但我试图远离它。
The GetRolesForUser()
method in the RoleProvider
takes the user login name and returns the list of roles for that user. But in my application this is not enough, I need a few more pieces of information to be able to get the user's roles.
How can I get this extra information into the method?
I have it in the Session
, but I found out that Session
is not available in the RoleProvider
.
What I had in mind was putting this extra info in some class that extends MembershipUser
, assuming I can get to it inside the RoleProvider
. But I don't know how to create the CustomMembershipUser
and make it part of the MembershipProvider
. Is this even possible?
The easy way out would be using cookies, but I'm trying to keep away from it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此问题的解决方案:使用 cookie 来存储
RoleProvider
所需的任何额外信息。The solution to this problem: using a cookie to store any extra information needed by the
RoleProvider
.您可以在
HttpContext.Current.Items
数组中存储和检索内容,该数组可在RoleProvider
中使用,这与 Session 不同。You can store and retrieve things in the
HttpContext.Current.Items
array, that IS available in theRoleProvider
, unlike Session.我知道这是一个老问题,但我只是想建议每个服务使用特定的角色。因此,您不再有 Administrator、Manager 和 User 之类的东西,而是有 Service1_Administrator、Service2_Administrator、Service1_Manager、Service2_Manager、Service1_User、Service2_User 等。
您是如何解决这个问题的?
I know this is an old question but I just wanted to suggest using specific roles per service. So instead of having something like Administrator, Manager, and User you'd have Service1_Administrator, Service2_Administrator, Service1_Manager, Service2_Manager, Service1_User, Service2_User, etc.
How did you solve it?