Skip to content

Instantly share code, notes, and snippets.

@gimmi
Created October 20, 2013 14:21
Show Gist options
  • Save gimmi/7070287 to your computer and use it in GitHub Desktop.
Save gimmi/7070287 to your computer and use it in GitHub Desktop.
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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment