is now This post has been archived at a GitHub Repository at

Using Generic Http Handlers to Speed Up ASP.Net - Writing XML

ASP.Net Page vs. Generic HTTP Handler

Web forms (aspx files) and web controls (ascx files) that populate the forms are the two most common elements we create in an ASP.Net web applications.  Web forms are great. You put in some <asp:tags /> and ASP.Net does the rest to render the HTML, and it's done in a lot less lines than you would have to write with classic ASP 3.0. With all this magic, however, there is a lot that happens behind the curtains.  There are 11 events that take place during the loading of an ASP.Net page. A Generic .ashx handler just has the ProcessRequest method.

XML Output

For something like writing raw XML to the browser which may not have any page controls like buttons or images, this is a perfect example of where you can benefit from the performance gain by using a generic http handler instead of wiring up events you won't use with an .aspx page.  The code to output the XML is fairly simple.

public class Handler : IHttpHandler 
      public void ProcessRequest (HttpContext context) 
           context.Response.ContentType = "text/xml";

      public bool IsReusable 
           get { return false; }
You should notice at least a 5 - 10% improvement in performance versus an page.