Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [330]

By Root 5672 0
An HTTP module component is a class that implements the IHttpModule interface. Modules can be considered the managed counterpart of ISAPI filters; they are kind of request interceptors with the built-in capability of modifying the overall context of the request being processed. The Microsoft .NET Framework defines a number of standard modules, as listed in Table 16-2. Custom modules can be defined too. I cover this particular aspect of HTTP programming in Chapter 18.

Table 16-2. ASP.NET Modules

Module

Description

AnonymousIdentification

Assigns anonymous users a fake identity.

FileAuthorization

Verifies that the remote user has Microsoft Windows NT permissions to access the requested resource.

FormsAuthentication

Enables applications to use forms authentication.

OutputCache

Provides page output caching services.

PassportAuthentication

Provides a wrapper around Passport authentication services.

Profile

Provides user profile services.

RoleManager

Provides session-state services for the application.

ScriptModule

Used to implement page methods in AJAX pages.

SessionState

Provides session-state services for the application.

UrlAuthorization

Provides URL-based authorization services to access specified resources.

UrlRouting

Provides support for URL routing

WindowsAuthentication

Enables ASP.NET applications to use Windows and Internet Information Services (IIS)-based authentication.

The list of default modules is defined in the machine.config file. By creating a proper web.config file, you can also create an application-specific list of modules. (Configuration is covered in Chapter 3.)

Methods of the HttpApplication Class


The methods of the HttpApplication class can be divided into two groups: operational methods and event handler managers. The HttpApplication operational methods are described in Table 16-3.

Table 16-3. HttpApplication Operational Methods

Method

Description

CompleteRequest

Sets an internal flag that causes ASP.NET to skip all successive steps in the pipeline and directly execute EndRequest. It’s mostly useful to HTTP modules.

Dispose

Overridable method, cleans up the instance variables of all registered modules after the request has been served. At this time, Request, Response, Session, and Application are no longer available.

GetOutputCacheProviderName

Overridable method, returns the currently configured provider for handling output page caching. (I’ll say more about output page caching in Chapter 18.)

GetVaryByCustomString

Overridable method, provides a way to set output caching based on a custom string for all pages in the application. (I’ll say more about output page caching in Chapter 18.)

Init

Overridable method that executes custom initialization code after all modules have been linked to the application to serve the request. You can use it to create and configure any object that you want to use throughout the request processing. At this time, Request, Response, Session, and Application are not yet available.

Note that the Init and Dispose methods are quite different from well-known event handlers such as Application_Start and Application_End.

Init executes for every request directed to the Web application, whereas Application_Start fires only once in the Web application’s lifetime. Init indicates that a new instance of the HttpApplication class has been initialized to serve an incoming request; Application_Start denotes that the first instance of the HttpApplication class has been created to start up the Web application and serve its very first request. Likewise, Dispose signals the next termination of the request processing but not necessarily the end of the application. Application_End is raised only once, when the application is being shut down.

Note

The lifetime of any resources created in the Init method is limited to the execution of the current request. Any resource you allocate in Init should be disposed of in Dispose, at the latest. If you need persistent data, resort to other objects that form the

Return Main Page Previous Page Next Page

®Online Book Reader