Created
October 20, 2013 14:21
-
-
Save gimmi/7070287 to your computer and use it in GitHub Desktop.
Registering IHttpHandler with RouteTable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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