5

I posted this question about 8 months ago. The accepted answer touches on some of the things you would miss out on by not playing by the default provider's rules. For example, if you do not use a custom RoleProvider that inherits from RoleProvider, you lose the ability to use quick shortcuts like User.IsInRole() . The answer refers to things like this as "built-in plumbing."

What I wish to know is where I can find a complete list of stuff that relies on this "built-in plumbing", and something that shows to which overriden methods they are calling behind the scenes.

For example, HttpContext.Current.User.IsInRole() is (I assume) referring to and calling my overriden "IsUserInRole()" method in my custom RoleProvider, but I would like to see the documentation where it is explicitly stated that HttpContext.Current.User.IsInRole() is actually calling IsUserInRole(), for all such methods for all providers.

I understand that it should be kind of obvious already (IsInRole() and IsUserInRole() are so similar), but my motivation for asking is to see and learn about the other kinds of such shortcuts that are available that I'm not even aware of. I have a feeling that I've re-invented the wheel several times, and I don't even know it.

Community
  • 1
  • 1
CptSupermrkt
  • 6,844
  • 12
  • 56
  • 87

1 Answers1

0

They aren't really the same, but whatever role provider you use will likely populate the current user's role collection to contain all the roles of the provider.

HttpContext.Current.User is an IPrincipal which you can read about here: http://msdn.microsoft.com/en-us/library/system.security.principal.aspx

This is a .NET convention for Identity in any .NET application (including ASP.NET of course). The only way you might be sure that the implementation of IPrincipal you are using is calling the same function of your RoleProvider is by using one that actually comes with your provider.

Role providers are instantiated per httpApplication object ( http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx ) and available for use by an Principal implementation.

Look at the Remarks section of this MSDN article: http://msdn.microsoft.com/en-us/library/bb340078.aspx The calling of the IsUserInRole of the role provider by IsInRole of the Principal is purely up to the implementation of your Principal provider.

Michael Dunlap
  • 4,300
  • 25
  • 36