Dissecting Razor, part 2: Gluing the pieces together

Last time, we saw that ASP.Net Web Pages are implemented in two independent assemblies. These assemblies are not directly connected to each-other.

Razor Side

System.Web.WebPages.Razor.dll contains the RazorBuildProvider class, which allows ASP.Net’s build system to compile Razor pages.  This class uses a WebRazorHostFactory to create WebPageRazorHosts used to process CSHTML (or VBHTML) files into CodeDOM trees.  It compiles the CodeDOM tree and returns the generated type(which will typically inherit System.Web.WebPages.WebPage) to the build system.

WebPageRazorHost is coupled to the WebPages framework; it handles the non-standard base types for special pages (StartPage and ApplicationStartPage).

RazorBuildProvider can be configured to use a different WebRazorHostFactory that creates custom WebPageRazorHosts.  (more on this later)

WebPages Side

The WebPages framework contains an internal WebPageHttpModule class which runs when an ASP.Net AppDomain is started.  It runs any _AppStart files, and hooks the request lifecycle to handle requests for CSHTML (or VBHTML) pages.

Requests for Razor pages are handled by System.Web.WebPages.WebPageHttpHandler.  This class passes the page’s virtual path to the build manager and gets a WebPage instance (It assumes that RazorBuildProvider will build the page and give a WebPage instance). 

The handler calls the page’s ExecutePageHierarchy method to serve the page to the client.  This method runs any _PageStart pages in the page’s parent directories, then executes the page.

The WebPageHttpHandler will also add a custom HTTP header, X-AspNetWebPages-Version: 1.0.  This can be disabled by setting WebPageHttpHandler.DisableWebPagesResponseHeader to false.

As mentioned, System.Web.WebPages.dll is not directly tied to the Razor language and engine.  One can create a custom build provider which compiles classes that inherit WebPage, then call WebPageHttpHandler.RegisterExtension to tell the WebPages framework to handle requests to the extension, without using the Razor parser.

The source code for this project is part of the same bundle.

Next time: MVC Razor views


Such blogs are great to read. Susy

Try to have a look at these advices if you want to know the best UK university. It was useful to read for me and my college friends

I recently ran over your site and have been reading along the blog you have made. I figured I would leave my first comment. I might want to thank you for the efforts you have made in writing this article. I trust a similar best work from you later on also. Truth is told your creative writing capacities have motivated me to begin my own blog now. Here you can check out my best essay writing service to having a wonderful support for your writing.

Hi there! Thanks for sharing this type of interesting information. If you are a student who is constantly assigned academic papers, make sure you have full access to our academic essays database and essays database online.

Schbase, thanks man for giving the detailed information of ASP.net .For the beginners its very tough to understand these languages as there is lot of complexity in these tools .When I was begin my development job in essay writing service firm I faced a lot of troubles but with the passage learnt all the things from seniors .

mr jatt Mp3 New Punjabi Song,Single Tracks Latest song download also Listen Latest Music Albums Online in High Quality at Mrpendus.in
mr jatt

Nowadays everybody can easily improve writing skills. There are nothing difficulties, simply need to concentrate on the mind. Think positive and write anything on anyway from your mind. Another solution is you need to search online for some new ideas or creativity things and also you need to read articles. I'm a freelancer and I must develop my writing skills because I writing avatar movie review essay and it helps begin to see your writing mistakes and develop your member and mind.

Legitimate creative assignment writing service has become very popular among students seeking Custom Creative Writing Services and creative research paper writing services.

I know that nowadays many people use help of professional resume service. It seems to me, great idea. One o these services is https://essaysworld.net/resume-writing-service. You can rely on professional writers from this service.

Post a Comment