I hope to try this a bit later, but for now I’ll just talk about my thoughts:
In web pages, Razor works by registering a BuildProvider using an ASP.NET build assembly for .cshtml and .vbhtml.
Web pages, in turn, register .cshtml.vbhtml extensions for their handler.
When a web page page is requested, System.Web.WebPages.WebPageHttpHandler passes the path to the assembly pipe, where the extensions are mapped to the registered Razor provider, which displays the page and passes the WebPage object, which passes the handler for IIS and is served.
You will see all this if you use the reflection tool. Both of these are achieved in the PreApplicationStartCode.Start () of the corresponding assembly.
Razor hooks up its build vendor:
public static void Start() { if (!_startWasCalled) { _startWasCalled = true; BuildProvider.RegisterBuildProvider(".cshtml", typeof(RazorBuildProvider)); BuildProvider.RegisterBuildProvider(".vbhtml", typeof(RazorBuildProvider)); } }
Web pages connecting WebPageHandler
public static void Start() { if (!_startWasCalled) { _startWasCalled = true; WebPageHttpHandler.RegisterExtension("cshtml"); WebPageHttpHandler.RegisterExtension("vbhtml"); PageParser.EnableLongStringsAsResources = false; DynamicModuleUtility.RegisterModule(typeof(WebPageHttpModule)); ScopeStorage.CurrentProvider = new AspNetRequestScopeStorageProvider(); } }
To override, we need to create and register a separate BuildProvider using an ASP.NET channel to display our pages. System.Web.WebPages provides the WebPageHttpHandler.RegisterExtension () method, which theoretically allows you to connect another BuildProvider, for which a WebPage request will be received instead of a Razor request.
Several blogs mention the RegisterExtension method, but there is also an open connect error report showing that it does not work 100%. Perhaps it is more advisable to simply redefine everything and connect our buildprovider to the pipe (without using the method).
Web.config provides a construct for registering buildProviders, so I will try to try this.
<buildProviders> <add extension=".cshtml" type="CustomStuff.CustomBuildProvider"/> </buildProviders>
The problem is that most view engines use ViewEngines.Register (), a concept that does not seem to have web pages. Thus, we will have to wrap these viewing mechanisms in a BuildProvider and / or create a BuildProvider that can successfully invoke IViewEngine
Again, just share your thinking. I will try to register Spark or something later if I find some time.