Extending the RoleProvider GetRolesForUser()

爱⌒轻易说出口 提交于 2019-12-08 08:34:55

问题


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.


回答1:


The solution to this problem: using a cookie to store any extra information needed by the RoleProvider.




回答2:


You can store and retrieve things in the HttpContext.Current.Items array, that IS available in the RoleProvider, unlike Session.




回答3:


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?



来源:https://stackoverflow.com/questions/2965164/extending-the-roleprovider-getrolesforuser

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