標籤:des style blog http color os io strong ar
http://www.cnblogs.com/highend/archive/2011/04/14/aspnet_mvc3_web_pages.html
I:Web Pages 1.0中以“_”開頭的特別檔案(檔案命名時不區分大小寫)
綜上所述得知MVC3的APP初始化順序為:
(不排除本人未能發現的其他檔案類型,但目前據我所知道應用最廣的就這三個)
在Web Pages 1.0下,除非你顯式以”_”開頭命名View.否則你在請求”_”開頭的頁面時會遇到以下無法服務的頁面提示
(這圖在Razor文法基礎時就帖過了.這裡帖出來是讓大家溫故而知新)
關於*.cshtml產生的類名格式 絕大部分頁產生的程式集格式
頁面編譯都是以單獨頁面編譯為單個帶隨機字串的程式集,當然也可以採用先行編譯方式將n個頁編譯為1個程式集
II:關於多目錄下以”_”開頭的特殊檔案的執行順序
_appstart.cshtml僅能存在於根目錄(“~/”), 如果你在子目錄下放置_appstart.cshtml檔案的話.那麼該檔案就不會被App初始化時執行
當訪問~/somepage.cshtml時. 會先執行~/_pageStart.cshtml 然後在執行 ~/somepage.cshtml 當在複雜的子目錄環境下時:
~/_pageStart.cshtml
~/sub/_pageStart.cshtml
~/sub/somepage.cshtml
III:Web Pages 1.0脫離WebForms的啟動原理
首先Web Pages利用特性往本身程式集上與ASP.NET掛鈎 // SourceFile: AssemblyInfo.cs(System.Web.WebPages.dll) //AttributeClass: System.Web. PreApplicationStartMethodAttribute //特性介紹:為ASP.NET 其他Provide提供擴充 //參數1: ASP.NET Provide的類型 //參數2:啟動並執行方法名 //Source: [assembly: PreApplicationStartMethod(typeof(System.Web.WebPages.PreApplicationStartCode), "Start")] //Line: 15 然後我們在這裡可以看到Web Pages的ASP.NET Provide是.Web.WebPages.PreApplicationStartCode 啟動方法是Start
public static void Start() {
// Even though ASP.NET will only call each PreAppStart once, we sometimes internally call one
// another PreAppStart to ensure that things get initialized in the right order. ASP.NET does
// order so we have to guard against multiple calls.
// All Start calls are made on same thread, so no lock needed here.
if (_startWasCalled) {
return;
}
_startWasCalled = true; //設定Start方法已被調用
WebPageHttpHandler.RegisterExtension("cshtml");//註冊擴充
WebPageHttpHandler.RegisterExtension("vbhtml");//註冊擴充
// Turn off the string resource behavior which would not work in our simple base page
PageParser.EnableLongStringsAsResources = false;//最佳化選項
DynamicModuleUtility.RegisterModule(typeof(WebPageHttpModule));//重點在這裡了.~~註冊了一個WebPageHttpModule
ScopeStorage.CurrentProvider = new AspNetRequestScopeStorageProvider();
//ASP.NET Web Pages的RequestScopeStorageProvider
}
ASP.NET MVC3 系列教程 – Web Pages 1.0