Quantcast

Using the CompilationMode Attribute to Boost Performance

Get the WebProNews Newsletter:
[ Business]

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.

Tag:

Add to Del.icio.us | Digg | Reddit | Furl

Bookmark WebProNews:

Mads Kristensen currently works as a Senior Developer at Traceworks located
in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in
2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and
web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/

Using the CompilationMode Attribute to Boost Performance
Comments Off
About Mads Kristensen
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/ WebProNews Writer
Top Rated White Papers and Resources

Comments are closed.