HTTP Handlers in ASP.NET

原创 2004年09月12日 19:55:00
HTTP Handlers in ASP.NET
Author Date Of Submission User Level
Sivakumar N 08/24/2004 Intermediate

Download: Examplehandler.rar 3Kb


The low level Request and Response API to service incoming Http requests are Http Handlers in Asp.Net. All handlers implement the IHttpHandler interface, which is located in the System.Web namespace. Handlers are somewhat analogous to Internet Server Application Programming Interface (ISAPI) extensions.

In this article, I will explain how to extend the functionality of web server by using Http handlers and How to protect files using Http handlers.

Methods in Http Handler

The following are the methods in Http Handlers.
Method Name Description
ProcessRequest Used o call Http Requests.
IsReusable To check the reusability of same instance handler with a new request of same type.

Configuring HTTP Handlers

The <httpHandlers> configuration section handler is responsible for mapping incoming URLs to the IHttpHandler or IHttpHandlerFactory class. It can be declared at the computer, site, or application level. Subdirectories inherit these settings.

Administrators use the <add> tag directive to configure the <httpHandlers> section. <Add> directives are interpreted and processed in a top-down sequential order. Use the following syntax for the <httpHandler> section handler:

<add verb="[verb list]" path="[path/wildcard]" type="[COM+ Class], [Assembly]" validate="[true/false]" />
<remove verb="[verb list]" path="[path/wildcard]" />
<clear />

Creating HTTP Handlers

To create an HTTP handler, you must implement the IHttpHandler interface. The IHttpHandler interface has one method and one property with the following signatures:
void ProcessRequest(HttpContext);
bool IsReusable {get;}

Customized Http Handler

By customizing http handlers, new functionalities can be added to Web Server. Files with new extensions like .text for a text file can be handled by Web Server by using http handlers. The future of customization can lead to hosting .jsp pages in IIS by finding adequate ISAPI extensions. The following steps are involved to create customized http handler:
1. Create a C# class library as 揈xamplehandler?br> 2. Name class as 揌andlerclass.cs?/font>

using System;
using System.Web;
using System.Web.SessionState;
namespace ExampleHandler
/// <summary>
/// Summary description for Examplehandler.
/// </summary>
public class Handlerclass : IHttpHandler
public Handlerclass()
// TODO: Add constructor logic here

#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
HttpResponse objResponse = context.Response ;
HttpSessionState objSession = context.Session ;
objResponse.Write("<html><body><h1>Hello World from Handler") ;
objResponse.Write("</body></html>") ;

public bool IsReusable
return true;

Compile it and place it in the bin directory of TestApp project.

Step 2

Register this handler by adding the following text in the web.config file:

<add verb="*" path="*.text" type=" ExampleHandler.Handlerclass, ExampleHandler "/>

Step 3

Go to Internet Information Services and select Default Web Site. Right Click and Select Properties. Select Home Directory and click on Configuration. The Following Screen will appear:

Click on Add and give executable path and new extension and click OK.

Close IIS and Run TestApp website by using the URL


The output will be as follows:


The sensitive files can be protected by Http Forbidden Handler. The Database driven web sites using MS Access, the .mdb file has to be protected. To protect the .mdb files, we must follow the two steps given below:

1. Map .mdb file in IIS

2. Register the file extension in web.config with HttpForbiddenHandler.

In the Web.Config file, Add this Http handler section:

<add verb="*" path="*.mdb" type="System.Web.HttpForbiddenHandler"/>


The Http Handlers are often useful when the services provided by the high-level page framework abstraction are not required for processing the HTTP request. Common uses of handlers include filters and CGI-like applications, especially those that return binary data.


  • winner005
  • winner005
  • 2015年03月11日 17:28
  • 1583

Openstack Kilo版本安装及问题总结

Openstack Kilo版本安装及问题总结
  • gsllovefly
  • gsllovefly
  • 2016年04月07日 10:34
  • 1671

ASP.NET Chart 实例 及 解决ChartImg.axd 执行子请求时出错

MSChart是VS中自带的图表控件,功能比较强大,效果也比较丰富。下面只提供一个例子,以供新接触的朋友参考。 先看下效果图: 看完效果图上代码啦。 使用这个控件需要先在页面注册一...
  • anihasiyou
  • anihasiyou
  • 2014年02月17日 22:39
  • 2185

ASP.NET异步请求处理(Asynchronous HTTP Handlers)

ASP.NET异步请求处理(Asynchronous HTTP Handlers) ASP.NET中你可以通过继承IHttpHandler这个接口来实现一个同步(Synchronou...
  • nic7968
  • nic7968
  • 2012年05月28日 23:54
  • 321

Sending Compressed HTTP Reponse in ASP.NET Web Application

  • 2009年11月07日 12:24
  • 15KB
  • 下载

File Upload using jQuery AJAX in ASP.NET Web API or Http handler (AJAX上传文件通过Web API或 http handler)

AJAX上传文件通过Web API或 http handler Upload file using jQuery AJAX in ASP.NET Web API This articl...
  • kingmax54212008
  • kingmax54212008
  • 2016年02月11日 08:20
  • 1401

user 'IIS APPPOOL\ASP.NET v4.0' error in IIS7问题的解决方法

How to Fix Login failed for user 'IIS APPPOOL\ASP.NET v4.0' error in IIS7 今天用silverligh...
  • tianhongmu
  • tianhongmu
  • 2012年05月10日 23:30
  • 1751

ASP.NET WebForm URL rewrite in VS2010

在C#2.0时期,要把 /Farm.aspx?farmid=1映射成/farm/1,需要借助IISRewriter或者其它第三方组件,也可以自己用代码定义路由规则,要修改web.config,甚至要写...
  • keepitshortandsimple
  • keepitshortandsimple
  • 2011年09月27日 16:09
  • 993

Running ASP.NET 5 applications in Linux Containers with Docker

As a part of our ASP.NET 5 cross-platform efforts, we are actively working on making applications wr...
  • afandaafandaafanda
  • afandaafandaafanda
  • 2015年10月09日 10:42
  • 702

jQuery Autocomplete with multiple fileds in Asp.Net C#

 This  article explains jQuery autocomplete with  multiple fields using Asp.Net C#.Scenario :  Listi...
  • xqsapper
  • xqsapper
  • 2011年06月18日 00:48
  • 134
您举报文章:HTTP Handlers in ASP.NET