0

I can setup custom membership easily enough, but what if I need two sets i.e. admin for control panel and registered for logged on customers. This would mean two seperate tables to get users from. My question is how can I integrate the two to control through 1 custom membership and how can I authenticate on the controller for the 2?

tereško
  • 58,060
  • 25
  • 98
  • 150
user1166905
  • 2,612
  • 7
  • 43
  • 75
  • 1
    This seems to me like two different roles more than two different memberships. Can't you simply use admin and customer roles to differenciate your users? – Bardo Sep 24 '12 at 11:12

1 Answers1

1

You wouldn't separate users this way, you'd implement a custom role provider and allocate these roles to the user. So say you have created two roles admin and user you'd set an attribute to your controller like so:

Admin page controller

[Authorize(Roles = "Admin")]
public ActionResult AdminAction() { }

User page controller

[Authorize(Roles = "User")]
public ActionResult UserAction() { }

If you wanted your administrators to view all logged in user pages, you'd simply just assign the user role to your administrators.

Paul Aldred-Bann
  • 5,840
  • 4
  • 36
  • 55
  • Thats great and what I envisaged but my mind is blank on how to define the roles, I don't want to create a roles table, if possible would like to change the ValidateUser() of custom membership to check which table to use for admin/user and set the role manually here, possible? – user1166905 Sep 24 '12 at 11:23
  • 1
    @user1166905 you could create a custom `MembershipUser` (http://stackoverflow.com/questions/912121/implementing-custom-membershipuser) with a `Roles` attribute (maybe a comma delimited string) that is set in your `ValidateUser()` method based on where they came from. Then you could create a custom attribute (http://www.codeproject.com/Articles/2933/Attributes-in-C) where this attribute would take the role name as a string and then query your custom user class for the respective role. – Paul Aldred-Bann Sep 24 '12 at 11:27