DefaultAuthenticationModule Class
Assembly: System.Web (in system.web.dll)
The DefaultAuthenticationModule ensures that the User property of the current HttpContext instance is set to an IPrincipal object for each request. The DefaultAuthenticationModule examines the User property after the AuthenticateRequest event and before the AuthorizeRequest event. If the User property is a null reference (Nothing in Visual Basic), the DefaultAuthenticationModule sets the User property to a GenericPrincipal object that contains no user information.
If the authentication module sets the StatusCode property to 401, the DefaultAuthenticationModule will render an access-denied error page. If the value of the StatusCode property is set to a value greater than 200, the DefaultAuthenticationModule object will end the request. In that case, only HTTP modules that subscribe to the EndRequest event are called prior to the completion of the current request.
The DefaultAuthenticationModule exposes an Authenticate event. You can use this event to provide a custom IPrincipal object for the User property of the current HttpContext instance. The Authenticate event is accessed by specifying an event named DefaultAuthentication_OnAuthenticate in the application's Global.asax file.
The following example uses the DefaultAuthentication_OnAuthenticate event to test whether the User property of the current HttpContext instance is a null reference (Nothing in Visual Basic). If the User property is a null reference (Nothing in Visual Basic), then the sample sets the User property of the current HttpContext instance to a GenericPrincipal object where the Identity of the GenericPrincipal object is a GenericIdentity with a Name value of "default."
Note: |
|---|
|
The DefaultAuthentication_OnAuthenticate event is raised before the AuthorizeRequest event. As a result, if you set the User property of the current HttpContext instance to a custom identity, it can affect the behavior of your application. For example, if you are using the FormsAuthentication class and you specify |
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
Note: