It depends from the implementation of IPrincipal
interface that stored in HttpContext.Current.User
.
If you use SqlMembership or Universal membership provider I believe that when you call IsInRole("Administrator")
it will hit your database. You can check it with SQL profiler for sure.
By the way you can set to HttpContext.Current.User
property your own implementation in
Application_PostAuthenticateRequest
method. Look here for more information.
UPDATE:
Let me clearify my answer.
By default asp.net grabs your role provider that goes with membership provider. So the first option to override IsInRole behavior is to write your own role provider (Look here for more information).
Another option would be to write your own implementation of IPrincipal like this:
public class CustomPrincipal : IPrincipal
{
public IIdentity Identity { get; private set; }
public bool IsInRole(string role) {
//Here goes your implementation of IsInRole
}
}
and hook it in Global.asax
Application_PostAuthenticateRequest
method:
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
//here you need to check is user authenticated, also you have opportunity to work with authentication ticket
HttpContext.Current.User = new CustomPrincipal();
}