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

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.

Published Friday, October 15, 2004 1:35 AM by Jon Galloway
Filed under:

Comments

# Precompile ASP.NET 1.1 web sites with System.Web.Handlers.BatchHandler

Thanks, Jon, for the tip. I'll definately hold onto this one.

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

Friday, October 15, 2004 10:01 AM by inventive title: rbuckton's blog

# Precompile your ASP.Net 1.1 web application

Friday, October 15, 2004 11:05 AM by TrackBack

# Precompile your ASP.Net 1.1 web application

Friday, October 15, 2004 11:05 AM by TrackBack

# Precompile ASP.NET 1.1 web sites with System.Web.Handlers.BatchHandler

Thanks, Jon, for the tip. I'll definately hold onto this one.

Friday, October 15, 2004 1:00 PM by TrackBack

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

#

Friday, October 15, 2004 2:32 PM by dotnetgeek

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

Wednesday, October 20, 2004 11:28 AM by TrackBack

# Precompile.axd

Tuesday, December 14, 2004 5:20 PM by TrackBack

# Precompile your ASP.Net 1.1 web application

browsing weblogs.asp.net i came across Jon Galloways blog entry about precompiling web applications....

Saturday, January 15, 2005 3:29 PM by TrackBack

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

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?

Friday, July 07, 2006 7:22 PM by Rchandra

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

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.

Tuesday, July 11, 2006 12:36 PM by Mythran

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

Just turn on batch compilation with the compilation element, batch attribute in web.config or machine.config. See http://msdn2.microsoft.com/en-us/library/s10awwz0.aspx

Monday, March 26, 2007 12:15 PM by Sean

Leave a Comment

(required) 
(required) 
(optional)
(required)