Precompile.axd in ASP.NET 1.1 with System.Web.Handlers.BatchHandler

[UPDATE: DotNetGeek tested this out and listed some probable reasons why the BatchHandler didn't make the cut for ASP.NET 1.1. It probably works fine for small code-front folder based sites, but doesn't work well with the VS 2003 project approach. As this project approach goes away a bit in ASP.NET 2.0, it may have been easier to implement precompile.axd. I still think it's pretty worthwhile to look through the handler code in Reflector, since it's some pretty slick stuff.]

ASP.NET 2.0 includes precompilation support, including in-place precompilation using a special handler - precompile.axd.

Precompilation is explained here [MSDN]. It's a a batch compile on the entire site including code-front logic contained in your ASPX files.

precompile.axd is a special handler, similar to trace.axd, that maps to a new HTTP handler, System.Web.Handlers.PrecompHandler (at last check).

While digging through System.Web.dll (ASP.NET 1.1) with Reflector (an odd hobby of mine), I noticed System.Web.Handlers.BatchHandler. BatchHandler appears to do pretty much the same thing PrecompHandler is described to do - it performs a batch compile on the Context.Request.BaseDir, a.k.a. the virtual root.

There's nothing hooked up to that BatchHandler, but connecting an HTTP handler to a filename is easy. You can either set this up at the server level (machine.config) or the application level (web.config).

To set this up at the machine level, add the following line to the <httpHandlers> section of %windir%\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config:

<add verb="*" path="precompile.axd" type="System.Web.Handlers.BatchHandler"/>

To set this up at the application level, add the you'll need to create an httpHandlers section like so:

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="precompile.axd" type="System.Web.Handlers.BatchHandler"/>
    </httpHandlers>
  </system.web>
</configuration>

Does it work? Well, it looks like it does.

Once the handler is configured, browsing to http://localhost/virtualDirectory/precompile.axd gives me this:

Batch compilation was successful!

That's a rather emphatic declaration of success... but this wasn't advertised in ASP.NET 1.1 so who knows. I'm still testing it out. Let me know how it works for you, or if you know more about the mysterious BatchHandler.

2 Comments

  • I used this technique and actually saw the "Batch compilation was successful!" message.

    I am sure I will find this out myself, but how long does the precompilation stick? By that I mean, do I need to recompile after every IIS restart, or even worse if the app has been idle for some time?


  • Just started using this technique. I think I wanna learn how this works ... so gonna be digging through it a little more (not handlers, but the BatchHandler itself).

    :) Awesome, thus far.

Comments have been disabled for this content.