One of the cool new features of ASP.NET 2.0 is that of having a precompiled site by the use of a command line tool called aspnet_compiler.exe. This tool will allow your site be compiled with out any source in your pages. What do I mean by that, well if you use the tool the output will be all of your .aspx pages with no HTML source in them. All the source is taken and compiled into the code behind of the html-part (view) of the page. This feature will allow you to pre-compile a site that is rarely updated and have minimal deployment for it. More importantly it also allows you to decrease the performance hit your first request takes since it eliminates the compilation step taken by the ASP.NET runtime (there are more benefits, but this is the quicker one to explain).
If you don't want to pre-compile your application using the command line tool, you can also use a new handler that will the same thing for you. The name of the handler is precompile.axd. To use it, you just call it via the url for application. In other words, if you application url is http://mydomain.com, you will call the handler by using http://mydomain.com/precompile.axd. This way, when you make the call you're the first one to make a call to your application and all of your user controls and pages will be compiled under the same assembly (rather then in individual assemblies for every page).
Ok, what does this have to do with ASP.NET 1.1? To make a long story even longer, you can use one of these precompile features in your current ASP.NET apps by making a simple change to your .config file. Sorry, it's not the aspnet_compiler.exe feature!
To enable precompilation with an ASP.NET handler, you need to add a new handler definition to either your web.config or machine.config. Under the System.Web.Handlers
namespace, there's an internal class (thanks Reflector!) called BatchHandler. This batch handler, well ... does what it names says ... batch compiles your application when you call it within the current application context. How do we do this? Here's how:
- Add the following handler definition to your web.config or machine.config:
<add path="precompile.axd" type="System.Web.Handlers.BatchHandler" verb="*" />
- Hit the handler by using the direct url to your application:
http://localhost/myApp/precompile.axd
- Sit back and wait until you see the following text: Batch compilation was successful!
I've included a demo project with this application that has the handler defined within the web.config for any one to test with. I hope you enjoy this tip!