imak
imak

Reputation: 6699

when to write handler or module.. any examples?

I have read about these but still confused what are the uses cases where I will write a http handler and not http module ( and vice versa). A few example of uses cases for each will help

Upvotes: 3

Views: 1376

Answers (2)

Martin Buberl
Martin Buberl

Reputation: 47164

HTTP Handlers and HTTP Modules Overview

Typical uses for custom HTTP handlers include the following:

  • RSS feeds To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. You can then bind a file name extension such as .rss to the custom handler. When users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.

  • Image server If you want a Web application to serve images in a variety of sizes, you can write a custom handler to resize images and then send them to the user as the handler's response.

Typical uses for HTTP modules include the following:

  • Security Because you can examine incoming requests, an HTTP module can perform custom authentication or other security checks before the requested page, XML Web service, or handler is called. In Internet Information Services (IIS) 7.0 running in Integrated mode, you can extend forms authentication to all content types in an application.

  • Statistics and logging Because HTTP modules are called on every request, you can gather request statistics and log information in a centralized module, instead of in individual pages.

  • Custom headers or footers Because you can modify the outgoing response, you can insert content such as custom header information into every page or XML Web service response.

Upvotes: 1

David
David

Reputation: 34573

An HTTP handler is like an ASPX page. A handler is registered in your web.config to respond to a particular URL such as "*.css" or "MyHandler.xyz".

An HTTP module processes all requests. If you need to handle something for all of your requests before they start being processed by their handler, then you want an HTTP module. Security and caching are the main examples for using a module.

Upvotes: 0

Related Questions