Registering IHttpHandler with RouteTable
using System;
using System.Web;
using System.Web.Routing;
namespace WebApplication1
{
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new Route("ping/light", new PingLightHttpHandler()));
RouteTable.Routes.Add(new Route("ping", new PingHttpHandler()));
}
public class PingHttpHandler : IHttpHandler, IRouteHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Handled by " + GetType().Name);
}
public bool IsReusable
{
get { return true; }
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return this;
}
}
public class PingLightHttpHandler : IHttpHandler, IRouteHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Handled by " + GetType().Name);
}
public bool IsReusable
{
get { return true; }
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return this;
}
}
}
}