ApplicationParts are a feature in ASP.Net WebPages that allow you to register and execute precompiled webpages as regular pages. The _Admin module and the Razor debugger (http://nuget.org/List/Packages/RazorDebugger) are examples of precompiled web pages. To generate precompiled websites specify the host property as WebPages.
@* Generator: WebPage *@
Once compiled, notice that the generated class has a PageVirtualPath attribute. The value of this attribute is derived from the project-relative path of the file. This determines the path to this page in a application where it is registered.
[System.Web.WebPages.PageVirtualPathAttribute("~/WebPagesSample.cshtml")] public class WebPagesSample_cshtml : System.Web.WebPages.WebPage
Once you’ve precompiled your pages, you need to write bootstrapping code that registers the assembly as an ApplicationPart. One way to go about this is to write a PreApplicationStartMethod.
// AssemblyInfo.cs [assembly: PreApplicationStartMethod(typeof(PrecompiledTest.PreApplicationStartCode), "Start")] // PreApplicationStartCode.cs using System.Web; namespace PrecompiledTest { public static class PreApplicationStartCode() { private static bool _startCalled; public static void Start() { public static void Start() { if (_startMethodExecuted == true) { return; } string root = "~/MyModuleRoot"; ApplicationPart.Register(new ApplicationPart(typeof(PreApplicationStartCode).Assembly, root)); } } }
Pages from your precompiled assembly would now be available under the root path that you specified e.g. ~/MyModuleRoot/WebPagesSample