HTTP Handlers in ASP.NET

0 views
Skip to first unread message

dinas...@gmail.com

unread,
Nov 16, 2006, 8:16:02 AM11/16/06
to WEB开发技巧回收站
Steps involved in implementing our HTTP handler are as follows:

Write a class which implements IHttpHandler interface
Register this handler in web.config or machine.config file.
Map the file extension to ASP.NET ISAPI extension DLL
(aspnet_isapi.dll) in Internet Services Manager.
我习惯的流程(也是运行时处理的流程):

1、当然是IIS了,映射要处理的文件扩展名到aspnet_isapi.dll

2、在web.config里面设置处理程序

<httpHandlers>
<add verb="supported http verbs" path="path" type="namespace.classname,
assemblyname" />
<httpHandlers>

verb:get,post,*
path:匹配的文件名
type:处理的程序

3、编写处理程序

从IHttpHandler继承,页面自动调用ProcessRequest(System.Web.HttpContext
context)
As you can see in the ProcessRequest method, the HTTP handler has
access to all ASP.NET intrinsic objects passed to it in its parameter
through the System.Web.HttpContext object. Implementing the
ProcessRequest method is simply extracting the HttpResponse object from
the context object and then sending some HTML out to the client.
Similarly, IsReusable returns true to designate that this handler can
be reused for processing the other HTTP requests.

using System;
using System.Web;

namespace MyHandler
{
/// <summary>
/// Summary description for NewHandler.
/// </summary>
public class NewHandler : IHttpHandler
{
public NewHandler()
{
//
// TODO: Add constructor logic here
//
}

#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{
HttpResponse objResponse = context.Response ;
objResponse.Write("<html><body><h1>Hello Reader ") ;
objResponse.Write("</body></html>") ;
}

public bool IsReusable
{
get
{
return true;
}
}
#endregion
}
}

Reply all
Reply to author
Forward
0 new messages