ASP.NET 2.0 introduced the CompilationMode attribute to let the developers decide how to compile individual pages, user controls and master pages. You can set the value to these three values:

  • Always
  • Auto
  • Never

This is the definition from MSDN:

"The CompilationMode enumeration values indicate whether a page or control should be compiled at run time. When no compilation mode is specified, the default value is Always. Setting a page to never compile using the Never attribute will increase performance by disqualifying the specified page in the compilation process."

The attribute can be set on the individual page and control declarations like this:

<%@ Page compilationMode=”Never” %>
<%@ Control CompilationMode="Never" %>

Or in the web.config’s system.web section.

<pages compilationMode="Auto" />

If you set the CompilationMode to Never on a page, that page will never get compiled. If there is any C#/VB code on that page an error will be thrown. I use it for user controls that don’t have any code, but still hosts various controls like other user/custom controls or the built-in Login control. If there are lesser pages to compile, you get a slight performance boost.

I recommend that you don’t use the web.config to set the CompilationMode, but on the individual pages and controls to avoid surprises. However, if you want to apply this to an already existing web application it’s much easier to set the CompilationMode to Auto in the web.config depending on the size of the web application.

Comments


Comments are closed