1

Is it possible to override the logic IsInRole in asp.net? I use my own tables of roles in the database and I would like to know how to use own logic.

Something like inheriting from PrincipialBase. Do you know some ways?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kovpaev Alexey
  • 1,725
  • 6
  • 19
  • 38

3 Answers3

3

I would only use RoleProvider if you are using other aspects of ASP.NET authentication and authorization management. However, if you have your own database for storing role information and already have a UI for managing user roles, you can get away with just creating a GenericPrincipal with your roles and replacing HttpContext.Current.User with it during PostAuthenticateRequest (for ASP.NET).

MVC is slightly different, depending on how you are managing authorization. Here is a related question.

application role management in asp.net mvc (How)?

It is better to load all the roles for a user once per request then to check roles against the database multiple times during the request.

Community
  • 1
  • 1
Joe Enzminger
  • 11,110
  • 3
  • 50
  • 75
2

Then you need to implement a custom RoleProvider. Here is a guide to implement a RoleProvider.

Eranga
  • 32,181
  • 5
  • 97
  • 96
0

Microsoft released the source code for the default providers (membership, role, etc...). That is also a great reference when implementing your own provider. The one time I implemented a custom role provider, it served me very well.

santiagoIT
  • 9,411
  • 6
  • 46
  • 57
  • Unfortunately links at the specified page are broken. – Kovpaev Alexey Jan 18 '12 at 03:11
  • 1
    I just tried and they do work. Here is the download URL just in case http://download.microsoft.com/download/a/b/3/ab3c284b-dc9a-473d-b7e3-33bacfcc8e98/ProviderToolkitSamples.msi – santiagoIT Jan 18 '12 at 03:20