1

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.

Community
  • 1
  • 1
Farinha
  • 17,636
  • 21
  • 64
  • 80
  • I'm curious as to why you need more than just the user name. Surely a user name always uniquely identifies a user in any credential store, that's why Microsoft designed the API that way. – Christian Hayter Jun 03 '10 at 10:49
  • Because the application supports several "services" and a user can have access to more than one service, with a different set of roles in each of them. – Farinha Jun 03 '10 at 13:52

3 Answers3

2

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

Farinha
  • 17,636
  • 21
  • 64
  • 80
1

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

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
0

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?

mikesigs
  • 10,491
  • 3
  • 33
  • 40
  • 1
    I solved it by adding the service identifier to a cookie and then access it in the Role Provider to get the correct roles. – Farinha Mar 19 '11 at 11:08