ASP.NET MVC3 系列教程 – Web Pages 1.0

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.