1
votes

Friends,

Looking for some help in below situation:

A user of the systems has multiple roles -- Role A and Role B.

With Role A -- a user can access views -- PageA, PageB.

With Role B -- a user can access views -- PageP, PageQ.

I have a user with both Roles -- Role A and Role B with default Role as Role A. Problem: When a user is logged into the system with both roles and Default Role as Role A user should be able to access views -- PageA & PageB. I would like to have a drop down in the layout to show the roles of that user. When the role in the dropdown is changed to Role B then user should be able to access views PageP & PageQ and vice-versa.

Is it possible to do it using a Custom Role Provider and windows authentication with Asp.Net MVC ?

Any ideas are welcome.

Thanks in Advance, DC

1

1 Answers

1
votes

Behind the scene of Role Provider - If a new page is requested, a user's assigned roles are saved in IPrincipal on Current Thread. It happens in very early stage of page life cycle.

You should not remove/assign roles to IPrincipal in the middle of page life cycle.

When the role in the dropdown is changed to Role B then user should be able to access views PageP & PageQ and vice-versa.

In order to achieve it, you do not want to manipulate IPrincipal object.

Instead, please use simple logic such as

  1. Populate user's assigned role to DropDownList
  2. If Role A is selected, display PageA, PageB
  3. If Role B is selected, display PageP, PageQ