Click here to Skip to main content
13,248,112 members (38,689 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 24 May 2004

Yet another pre-compile tool for ASP.NET web sites

, 24 May 2004
Rate this:
Please Sign up or sign in to vote.
This article describes a VB.NET tool that make easier to pre-compile an ASP.NET site.


I know: the problem of pre-compiling an ASP.NET web site in order to avoid the classic "compilation delay" felt by the first user browsing those site's pages has been faced many times, and a lot of solutions have been proposed to solve it. But, when I was looking for these solutions to a classic problem, I didn't find the one that I liked completely. So, I decided to develop my own ASP.NET precompiler.

Of course, now you are thinking: "Uff, yet another pre-compile tool for ASP.NET web sites". And you're so right that I decided to title my article exactly with the words you have in your mind. But... before you stop reading, take a look at some peculiarities of the tool I propose.


My starting point was the CodeProject article "Pre-Compile ASPX pages in .NET 1.1" by Narendra Naidu: there, the precompiling task was faced by simply adding to the web site a special ASP.NET page simulating an HttpWebRequest towards each ASPX page of the web site itself.

That was a nice and simple solution, but not suitable in my specific situation. In fact, I was looking for:

  • something not implemented as a part of the web site, but as a separate application;
  • something not forcing me to precompile all the pages of my web site, but capable to focus only on a specific subset of them (for example, the most frequently used ones);
  • something working also with web sites protected by the ASP.NET Web Form Authentication mechanism;
  • something able to simulate client web requests coming from a specific browser;
  • something with the ability to keep track of compilation errors.

The ASP.NET precompiler I wrote matches all these goals, in fact:

  • it's a Windows Forms application, that doesn't force you to include the precompiler logic inside the web site itself;
  • it doesn't retrieve the pages to visit recursively walking on the web application folders tree, but it takes them from a user-configurable list of URLs;
  • it works also with web sites protected by Web Form Authentication, supporting a specific POST of data to the Login page and correctly managing the client-side authentication cookie;
  • it can "impersonate" a specific user agent, allowing you to work also with sites where some browser checks are implemented to force a navigation restriction;
  • it logs any error occurring during HTTP requests, that is very useful if - for some reason (for example, to have a more flexible deploying strategy) - you are not compiling your site's code-behind pages into a DLL assembly (that is: you're taking advantage of the src attribute of the @Page directive).

How to use the tool

As stated before, the tool forces the compilation of ASPX files just invoking their URLs in a web request. The list of the URLs to be hit is stored in a user-editable text file, that we'll simply call "URL file". The format of the URL file is simple: it stores an URL on each line, separating with a TAB character the base URL part from the relative path of the ASPX page. This split URL paths make simpler to invoke the same set of pages on different web sites (this is useful, for example, if you have various copies of the same ASP.NET site on different environments).

To create the URL file, you can use ASP.NET precompiler itself: select the "Generate URLs" option from the "File" menu and specify: the physical location of your web site's files, the base URL that will precede the relative page path in the final URL, and the filename for your new URL file.

Generating URLs

ASP.NET precompiler will walk recursively the specified path looking for ASPX files and it will generate your URL file, that can be manually edited later (for example, to refine or limit the set of pages to be precompiled).

To make the ASP.NET precompiler less "invasive" on your site, you can adopt a trick I found in Narendra Naidu's article: by adding a Response.End() inside the pre-request event handler of Global.asax, you can abort the page processing and rendering when you call your pages with a special parameter (for example, PreCompile=true). In this way, the requests coming from ASP.NET precompiler will cause the page compilation but not the complete overhead of serving a complete web request.

Private Sub Global_PreRequestHandlerExecute(...) _
                 Handles MyBase.PreRequestHandlerExecute
  ' Prevent processing if page was called with a "PreCompile" parameter
  If Not Request("PreCompile") Is Nothing Then Response.End()
End Sub

If you are planning to use this trick, you'll need to check the "Include PreCompile parameter" option when generating the URLs list with ASP.NET precompiler. Also, keep in mind that the Global_PreRequestHandlerExecute() handler will be invoked for each page requested on your web application, and this might cause a little impact on the web site performance.

When the URL file is ready, before starting the pre-compilation process, you need to configure some parameters on the ASP.NET precompiler's main form:

ASP.NET Precompiler main form

  • specify the name of the URL file you are going to use;
  • if you need to simulate web request from a specific browser, fill the textbox User Agent with the correct user agent string;
  • if you plan to invoke the pages stored in the URL file substituting the original base URL path with another one, use the Alternative Web Root option;
  • if the site you're working on is protected by Web Form Authentication, use the Web Form Authentication option, specifying the relative path for the Login page and the parameters it expects; activating this option will produce a preliminary POST request to the Login page to obtain the authentication cookie for subsequent requests (don't forget to include the __VIEWSTATE parameter with a valid value in the POST params textbox);
  • if you want to log any error occurred during the compilation process, activate the Log errors option, specifying the filename for the log (that is an HTML-formatted file, for easy viewing in a browser window);
  • if you need to clear the error log or the cookies collection before compiling, use the Reset cookies or the Reset error log option respectively.

The configuration settings you just set can be saved to disk for future use. The reuse of ASP.NET Precompiler settings is accomplished by the options of the "File" menu (for the storage mechanism underlying the saving/retrieval of these data, see my article about managing configuration settings persistence).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Alberto Venditti
Technical Lead
Italy Italy
I was born in 1970.

My first computer experience dates back to early 80s, with a Sinclair ZX81.
From that time on, as many "friends" say, my IT-illness has increased year by year.

I graduated in Electronic Engineering and earned the following Microsoft certifications:
MCP, MCT, MCDBA, MCSD, MCAD, MCSD for .NET (early achiever).

I worked in IT as a developer, a teacher, a consultant, a technical writer, a technical leader.
IT knowledge applied to real life is my primary interest and focus.

You may also be interested in...


Comments and Discussions

GeneralEntering POST Params Pin
daleallenc30-Dec-08 8:00
memberdaleallenc30-Dec-08 8:00 
GeneralRe: Entering POST Params Pin
Alberto Venditti9-Jan-09 4:41
memberAlberto Venditti9-Jan-09 4:41 
GeneralRe: Entering POST Params Pin
daleallenc12-Jan-09 8:14
memberdaleallenc12-Jan-09 8:14 
GeneralRun from logon script or batch file Pin
daleallenc4-Aug-08 9:12
memberdaleallenc4-Aug-08 9:12 
AnswerRe: Run from logon script or batch file Pin
Alberto Venditti5-Aug-08 6:09
memberAlberto Venditti5-Aug-08 6:09 
GeneralRe: Run from logon script or batch file Pin
daleallenc6-Aug-08 4:25
memberdaleallenc6-Aug-08 4:25 
GeneralRe: Run from logon script or batch file [modified] Pin
Alberto Venditti6-Aug-08 4:42
memberAlberto Venditti6-Aug-08 4:42 
The code included in my preceding post is intended to "replace" the original content of MainForm_Load() procedure.
Maybe you're compiling the project with a newer version of Visual Studio or of the .NET Framework? The original code was for VS2003 and .NET 1.1 (and I only tested the proposed modifications on that original target).
Let me know, and we'll address the issue.

Ciao, AV

modified on Wednesday, August 6, 2008 11:49 AM

GeneralRe: Run from logon script or batch file Pin
daleallenc7-Aug-08 4:54
memberdaleallenc7-Aug-08 4:54 
GeneralRe: Run from logon script or batch file Pin
Alberto Venditti7-Aug-08 6:36
memberAlberto Venditti7-Aug-08 6:36 
GeneralRe: Run from logon script or batch file Pin
daleallenc7-Aug-08 9:52
memberdaleallenc7-Aug-08 9:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 25 May 2004
Article Copyright 2004 by Alberto Venditti
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid