0

This might be a stupid question to ask but I am kind of a confuse here I am working on an ASP.NET web forms application and I need to implement roles base access to users.

This application is working with Active Directory so there is no login forms and form base authentication and I can't use User.Identity to check the roles. I am getting roles from a stored procedure like 1 for admin 2 for user and I want to know if there is a way to implement it generically like set some attributes to add in the controls to show and hide them instead of go and implement if conditions in every form.

I am not sure if I presented my point clearly here or not but please let me know if you get the idea of what I am trying to say. Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jazz b
  • 437
  • 1
  • 6
  • 15
  • Can you inherit your webforms from a custom class? If so than you can make base class explicitly for your roles and let that classes inherited by `System.Web.UI.Page` – JB's Mar 19 '19 at 19:29
  • @Jackboys I think I can but I didn't see the point how it is going to help? – jazz b Mar 19 '19 at 19:31
  • Let say you have Employee role and Supervisor role, for all Employee role page you inherit by `EmployeePage` class and all Supervisor role page by `SupervisorPage`. Now `EmployeePage` and `SupervisorPage` will be inherited from `System.Web.UI.Page` and in `EmployeePage` and `SupervisorPage` `Page_Load` function you can place your authorization. – JB's Mar 19 '19 at 19:35
  • And for Authentication, you can call that SPROC from `Page_Load` and check the role, can be a naive solution, but make the job done – JB's Mar 19 '19 at 19:36
  • but for that case didn't I need to create multiple classes for each role ? and I have one page like which shows results of students and both employee and supervisor can see it but only supervisor can edit it how its going to work with that. – jazz b Mar 19 '19 at 19:39
  • Yes, for both roles you can make another class and control the visibility according to your need – JB's Mar 19 '19 at 19:46

0 Answers0