Farinha
Farinha

Reputation: 18091

Extending the RoleProvider GetRolesForUser()

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.

Upvotes: 1

Views: 1755

Answers (3)

Scott Stafford
Scott Stafford

Reputation: 44776

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

Upvotes: 1

Farinha
Farinha

Reputation: 18091

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

Upvotes: 2

mikesigs
mikesigs

Reputation: 11380

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?

Upvotes: 0

Related Questions