Whenever a request enters the ASP.NET pipeline it is associated with a security context, which includes information identifying the requestor. When using forms authentication, an authentication ticket is used as an identity token. The FormsAuthenticationModule
is responsible for determining the identity of the requestor, which it does during the AuthenticateRequest
event.
If a valid, non-expired authentication ticket is found, the FormsAuthenticationModule
decodes it to ascertain the requestor's identity. It creates a new GenericPrincipal
object and assigns this to the HttpContext.User
object. The purpose of a principal, like GenericPrincipal
, is to identify the authenticated user's name and what roles she belong to. This purpose is evident by the fact that all principal objects have an Identity
property and an IsInRole(roleName)
method. The FormsAuthenticationModule
, however, is not interested in recording role information and the GenericPrincipal
object it creates does not specify any roles.
If the Roles framework is enabled, the RoleManagerModule
HTTP Module steps in after the FormsAuthenticationModule
and identifies the authenticated user's roles during the PostAuthenticateRequest
event, which fires after the AuthenticateRequest
event. If the request is from an authenticated user, the RoleManagerModule
overwrites the GenericPrincipal
object created by the FormsAuthenticationModule
and replaces it with a RolePrincipal
object. The RolePrincipal
class uses the Roles API to determine what roles the user belongs to.
The following figure depicts the ASP.NET pipeline workflow when using forms authentication and the Roles framework. The FormsAuthenticationModule
executes first, identifies the user via her authentication ticket, and creates a new GenericPrincipal
object. Next, the RoleManagerModule
steps in and overwrites the GenericPrincipal
object with a RolePrincipal
object.
If an anonymous user visits the site, neither the FormsAuthenticationModule
nor the RoleManagerModule
creates a principal object.
The ASP.NET Pipeline Events for an Authenticated User When Using Forms Authentication and the Roles Framework