[ASPNET4]Add a HttpHandler to ASPNET4 site(IIS7)

First, create a new .net4.0 Class Library project, add reference to System.Web.dll. then add a new class file to the project named say MyHttpHandler.cs:

using System;
using System.Web;
namespace Xhinker.TableTopic {
    public class MyHttpHandler:System.Web.IHttpHandler {
        public bool IsReusable {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context) {
            context.Response.Write("good,very good,llalalala");
        }
    }
}

 

Now in your ASP.NET site project add a reference to this Class Library project. open Web.config file. Under <system.webServer> node. add

    <handlers>
      <add name="handlerTest" verb="*" path="myHandler.han"
           type="Xhinker.TableTopic.MyHttpHandler,TBHttpHandlers"/>
    </handlers>


Build the solution and it will work.  

Now, why do I bother to create a new HttpHandler?
Nowadays, so many new technology spawn our mind. but truly speaking, the most basic things last longer. and I think that a raw httpHandler will be great to serve as a restful service for Javascript.

blog comments powered by Disqus