Building HTTP Handlers in asp dot net

The World Wide Web (WWW) uses the Hypertext Transfer Protocol (HTTP) as the underlying protocol for communication. It is an application-level protocol that is responsible for establishing a connection between a client (browser) and a Web server and transmitting the information requested by the client. In fact, the day-to-day life of a Web server involves receiving requests from clients and responding to them by using HTTP.

ASP.NET works by dispatching the client requests to user-defined HTTP handler objects called HTTP handlers. With ASP.NET, you can create these user-defined HTTP handlers by implementing a .NET interface named IHttpHandler.

After you've created a user-defined handler, you can bind a specific URL request to the handler for handling specific requests. For example, you can bind a URL request for a file, with your name as an extension, to a user-defined handler for processing. However, if a specific URL request is not mapped to a handler, the default handler of ASP.NET handles it.

When you enter a URL in a browser, the browser builds an HTTP request and sends it to the address specified in the URL. While building the HTTP request, various methods are used. These methods indicate the purpose of the request.

These methods include the following:

Get: Used when a request for a particular page is made. When a user enters a link in the Address box of the browser or clicks a hyperlink, the HTTP Get method is used to build the HTTP request. The Get method is usually used when the request does not alter the state of a database.

Head: Used when a user wants to retrieve only the information about the document and not the document itself.

Post: Used when a user requests a resource that interacts with a database.

The Web server, which contains the requested page, performs necessary processing based on the method used for sending the request, and returns the page requested by the client. In addition to these methods, you can have a lower-level control over the processing of requests on the Web server. This is possible with the help of application programming interfaces (APIs).

ISAPI and HTTP Runtime

A number of APIs have been developed that enable developers to have lower-level control over the processing of requests on the Web server. For example, the Internet Services API (ISAPI) developed for IIS Web Server enables developers to create highperformance applications. At the same time, it enables developers to have low-level control over the way requests are processed by IIS. With ISAPI, you can create your own dynamic link libraries (DLLs) that specify the tasks
that need to be performed when a request is sent to the Web server.

The DLLs provided in ISAPI can be of two types, filters and extensions. Filters enable you to write code that can receive notifications from the Web server during the processing of a request. Thus, filters are used to alter the standard behavior of the Web server. You can use filters to perform tasks such as compressing and encrypting the data to be sent and authenticating a user. On the other hand, ISAPI extensions accept user requests, perform tasks such as retrieving data from a database and generating an HTML page, and send a response to the client.

In ASP.NET Web applications, low-level control over client requests is achieved by using the HTTP runtime. The HTTP runtime is built on the Common Language Runtime (CLR) of the .NET Framework, and provides an environment for processing requests.

Thus, the CLR replaces the ISAPI under IIS. The HTTP runtime performs various functions, including receiving requests from the client, resolving the address specified in the URL, and sending the request to the appropriate application for further processing of the request.

The HTTP runtime is capable of receiving multiple requests simultaneously. The applications are run in separate address spaces, thereby improving reliability and preventing cross-platform chaos. Therefore, the failure of a single Web application does not affect the working of the HTTP runtime.

Just like the ISAPI extensions and ISAPI filters, the HTTP runtime enables developers to have lower-level control over processing Web requests. However, unlike ISAPI, for which developers must know C++, the HTTP runtime is a cleaner model and enables developers to program in any .NET programming language. Therefore, ASP.NET prefers the CLR of the .NET Framework to the ISAPI architecture.

Architecture of the HTTP Runtime

The architecture of the HTTP runtime is similar to that of a pipeline. It is comprised of a number of HTTP modules and handlers. In simple terms, HTTP modules and HTTP handlers are classes created by developers that implement predefined interfaces of ASP.NET. When a client makes a request that results in executing a Web application, the request passes through a pipeline of HTTP modules.

HTTP modules enable a Web application to perform specific tasks, such as encrypting the data, performing custom authentication for providing access to the application, and managing the state of the client session and the application. After passing through a series of HTTP modules, the request is sent to the HTTP handler. An HTTP handler is a replacement for ISAPI extensions that receive the request, fetch the required data, and send the data in response to the request sent by the client.

ASP.NET provides higher-level programming models, such as Web services and Web Forms, which are implemented as HTTP handlers. The pipeline architecture of the HTTP runtime enables you to easily implement new functionality by adding new HTTP modules and handlers.

ASP.NET provides various interfaces that can be implemented for creating HTTP modules and HTTP handlers. For example, it provides the IHttpModule interface, which can be used to create modules that perform tasks related to security and compression.

State management functions are often implemented in HTTP modules so that they can be easily added or removed from the HTTP runtime pipeline. In addition to the IHttpModule interface, ASP.NET has the IHttpHandler interface that can be implemented by developers to create a lower-level HTTP handler that receives the request and performs various tasks.

HTTP is used to process requests for the ASP.NET pages. Because HTTP is a connectionless protocol, clients connect to servers only for the duration of HTTP requests. There must be a way in ASP.NET to manage connections within an application. To do so, ASP.NET generates one HttpContext object and passes it to HTTP handlers for each request that is serviced.

The HttpContext object provides a way to manage the connections within an application. This object maintains the information about the current request and also provides access to the Request, Response, and Server objects corresponding to a particular HTTP request. The Request object provides access to the values entered by a user while sending a request to the Web server.

For example, you may enter values in an HTML form and send a request to the Web server to look up the value in a table stored in a database. This value can be accessed by using the Request object. Similarly, you can use the Response object to send a response from the Web server to the client. The Server object provides methods that are used for processing the request.

For example, the Server object has the HtmlDecode method, which decodes the HTTP request sent by the client by removing the HTML characters from the request. You can use all of these
built-in objects and their methods to perform different tasks in your HTTP handlers.

RELATED POST

CREATING ASSEMBLIES WITH ASP.NET

BUILDING HANDLERS IN ASP.NET

INTERFACES AND CLASSES CREATION IN ASP.NET

CACHING IN ASP.NET

CACHING IN ASP.NET PART TWO

WIRE LESS APPLICATION WITH ASP.NET

SECURITY IN ASP.NET PART ONE

SECURITY IN ASP.NET PART TWO

LOCALIZING ASP.NET APPLICATIONS

DEPLOYING ASP.NET APPLICATIONS

ASP.NET CONFIGURATION SYSTEM

WEB SERVICES IN ASP.NET

WEB SERVICES PART TWO

WEB SERVICE INFRASTRUCTURE

WEB SERVICE INFRASTRUCTURE PART TWO

EXCHANGING MESSAGES IN ASP.NET

MICROSOFT HAIL STORM

SOAP AND DOT NET PART ONE

SOAP AND DOT NET PART TWO


No comments:

Post a Comment