To Compile or Not Compile

ASP.NET 2.0 allows developers to configure whether a page compiles or not.  Consider the following page directive:

<%@ Page Language="C#" CompilationMode="Never" %>

Setting the CompilationMode attribute to Never will disallow code on the page.  It will also prevent compilation to an assembly.  These pages can contain server controls or Expressions such as $AppSettings and $ConnectionStrings.

The main benefit is scalability.  In large web sites, this can avoid the need to compile high number of pages into assemblies.  Instead of compiling, these "no-compile" pages are processed by it's corresponding control builder which is preserved in memory for the life of the application.

You can also let ASP.NET determine if a page qualifies for "no-compile" automatically by making the following setting in web.config:

compilationMode_auto

Published Tuesday, July 17, 2007 7:15 PM by Palermo4
Filed under: , ,

Comments

# re: To Compile or Not Compile

Wednesday, July 18, 2007 12:03 AM by sergiotarrillo

Hi Palermo!

This is only for inline code, or  code file, code beside?

Saludo,

# re: To Compile or Not Compile

Wednesday, July 18, 2007 6:29 AM by OMG

If the CompilationMode is set to Never and a page contains a script block or code construct that requires compilation, ASP.NET will return with an error and the page will not run.

Reference: msdn2.microsoft.com/.../system.web.ui.compilationmode.aspx

# re: To Compile or Not Compile

Wednesday, July 18, 2007 10:25 AM by Palermo4

Sergio,

Regarding "inline code, or code file, code beside" - the point is - NONE of them are allowed!  No code is allowed in a no-compile page.

# re: To Compile or Not Compile

Wednesday, July 18, 2007 10:26 AM by Palermo4

OMG,

You are correct.  Pages set to "Never" are not allowed to contain ANY code.  Even an empty script block is forbidden.

# Blog Zaa &raquo; Blog Archive &raquo; To Compile or Not Compile

Saturday, July 28, 2007 6:22 AM by Blog Zaa » Blog Archive » To Compile or Not Compile

Pingback from  Blog Zaa  &raquo; Blog Archive   &raquo; To Compile or Not Compile

# re: To Compile or Not Compile

Sunday, August 12, 2007 1:53 PM by sergiotarrillo

Hi Palermo!

in which type of pages, could use it? (about?)

Saludos,

# re: To Compile or Not Compile

Sunday, August 12, 2007 3:34 PM by Palermo4

sergiotarrillo,

About, Contact Us, and any static page of content would be a benefit.  However, the use of <%$ %> expressions are allowed.  This would allow declarative use of even a GridView on the page - thus allowing dynamic content even though nothing is compiled.

Leave a Comment

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