Archive

Archive for February, 2011

ASP.NET Pre-Compilation, Virtual Path Providers and Resource Providers

February 11, 2011 Leave a comment

If your Pre-Compiled Website uses custom Virtual Path Providers and Resource Providers both serving content from the application database, you may run into a series of issues. I will try to highlight a few hacks and workarounds to get the website to a working state.

Fritz Onion’s January 2006 article in the MSDN Magazine’s Extreme ASP.NET column is a very good start to understand ASP.NET Pre-Compilation model. The summary of the article is this very table found in the MSDN magazine article.


  Deployment Mode
  All Source All Binary Updatable (mixed)
What compiles into a unique assembly App_Code directory
global.asax
.ascx and associated codebehind file (separate assembly for each user control)
.master and associated codebehind file (separate assembly for each master page)
All .aspx files and their code­behind files in a given directory (separate assembly per directory)
App_Code directory
global.asax
.ascx and .master files and their associated codebehind files
All .aspx files and their code­behind files in a given directory (separate assembly per directory)
App_Code directory (D)
global.asax (R)
.ascx and .master files (R)
codebehind files for .ascx and .master files (D)
All .aspx files in a given directory (separate assembly per directory) (R)
All codebehind files associated with .aspx files in a given directory (separate assembly per directory) (D)
When it’s compiled Request time Deployment time (R) = Compiled at request time
(D) = Compiled at deployment time

 

The full article can be read here.

Making Virtual Path Providers work with Pre-Compilation:

This is not officially supported by Microsoft, so use this at your own risk.

The first hack is about registering the Custom Virtual Path Provider with the Hosting Environment using private reflection detailed in Coskun SONALI’s article here.

If you deploy the Web Site in the ‘All Binary’ mode, you will be greeted with the error ‘The file <your file served by the virtual path provider> has not been pre-compiled, and cannot be requested.’. It turns out that pre-compilation module was looking into a file called PreCompiledApp.config. If you just flip the updateable flag to true (after the all binary pre-compilation) and it should start working.

Making custom Resource Providers work with Pre-Compilation:

The pre-compiled site should be working but some of the resource expressions may not be working and you may be having blank instead of the resource string values in the labels and other text controls. To be more precise Explicit Resource Expressions will be working whereas Implicit Resource Expressions will not be. Rick Strahl’s blog talks about the Implicit Resource Provider interface IImplicitResourceProvider. Implementing one you can get the Implicit Resource reference in expressions also working in a pre-complied web site.

You can read Rick Strahl’s blog entries here, here and here.

Resource Providers are invoked at compile time as well and not surprisingly Rick Strahl has blogged about the same here.

If you start implementing a custom resource provider start with Rick Strahl’s version here rather than the one here.

Advertisements