1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢(xún)
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      如何理解ASP.NETMVC中的WebPages

      今天就跟大家聊聊有關(guān)如何理解ASP.NET MVC 中的Web Pages,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

      站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到臨縣網(wǎng)站設(shè)計(jì)與臨縣網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類(lèi)型包括:網(wǎng)站制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國(guó)際域名空間、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋臨縣地區(qū)。

      I:Web Pages 1.0中以“_”開(kāi)頭的特別文件(文件命名時(shí)不區(qū)分大小寫(xiě))

      “_appstart.cshtml” & “_pagestart.cshtml” & “_viewstart.cshtml”

      _appstart.cshtml - 應(yīng)用程序啟動(dòng)時(shí)在Global. Application_Start方法后執(zhí)行

      功能:用于進(jìn)行App的初始化時(shí),需要進(jìn)行處理的內(nèi)容.例:向數(shù)據(jù)庫(kù)記錄系統(tǒng)初始化的一些信息

      功能與Global.Application_Start類(lèi)似,差別在于:Global的Start先執(zhí)行,然后在到該_appStart,值得注意的是在_appStart上下文中可以使用.NET4的dynamic新特性~~在聲明中,作為屬性、字段、索引器、參數(shù)、返回值或類(lèi)型約束的類(lèi)型。

      http://msdn.microsoft.com/zh-cn/library/dd264741.aspx

        @{      this.App.StartMessage = "App順利已啟動(dòng)了.恭喜!哈";      var error = this.App.Error as string;      if (error == null)      {          this.App.Error = "使用dynamic新特性之前.請(qǐng)先賦值~";          error = this.App.Error;          @*               在這里很遺憾地告訴大家.dynamic不支持智能感知               因?yàn)榫幾g無(wú)法100%準(zhǔn)確得知程序的執(zhí)行順序.              所以無(wú)法智能感知!          *@      }      // 在這里可以引用 App.Error動(dòng)態(tài)字段了.  }

      如何理解ASP.NET MVC 中的Web Pages

      //--------------------------------------------  @{      @* ~/Views/_ViewStart.cshtml *@      Response.Write(string.Format("

      {0}

      ", App.StartMessage));      Layout = "~/Views/Shared/_Layout.cshtml";  }

      如何理解ASP.NET MVC 中的Web Pages

      成員來(lái)自:

      at System.Web.WebPages.Razor.WebPageRazorHost

      at System.Web.WebPages.ApplicationStartPage

      _viewstart.cshtml - 單個(gè)View處理Request時(shí)執(zhí)行

      功能:或許你已經(jīng)聯(lián)想到了….Global的Page_Load(僅應(yīng)用于View)……

      執(zhí)行順序位于_appstart.cshtml之后.畢竟所除層次不同

      成員來(lái)自:

      at System.Web.Mvc.RazorViewEngine

      綜上所述得知MVC3的APP初始化順序?yàn)?

      如何理解ASP.NET MVC 中的Web Pages

      (不排除本人未能發(fā)現(xiàn)的其他文件類(lèi)型,但目前據(jù)我所知道應(yīng)用最廣的就這三個(gè))

      在Web Pages 1.0下,除非你顯式以”_”開(kāi)頭命名View.否則你在請(qǐng)求”_”開(kāi)頭的頁(yè)面時(shí)會(huì)遇到以下無(wú)法服務(wù)的頁(yè)面提示

      如何理解ASP.NET MVC 中的Web Pages

      (這圖在Razor語(yǔ)法基礎(chǔ)時(shí)就帖過(guò)了.這里帖出來(lái)是讓大家溫故而知新)

      關(guān)于*.cshtml生成的類(lèi)名格式

      絕大部分頁(yè)生成的程序集格式

      如何理解ASP.NET MVC 中的Web Pages

      頁(yè)面編譯都是以單獨(dú)頁(yè)面編譯為單個(gè)帶隨機(jī)字符串的程序集,當(dāng)然也可以采用預(yù)編譯方式將n個(gè)頁(yè)編譯為1個(gè)程序集

      II:關(guān)于多目錄下以”_”開(kāi)頭的特殊文件的執(zhí)行順序

      _appstart.cshtml僅能存在于根目錄(“~/”),

      如果你在子目錄下放置_appstart.cshtml文件的話.那么該文件就不會(huì)被App初始化時(shí)執(zhí)行

      當(dāng)訪問(wèn)~/somepage.cshtml時(shí).

      會(huì)先執(zhí)行~/_pageStart.cshtml

      然后在執(zhí)行 ~/somepage.cshtml

      當(dāng)在復(fù)雜的子目錄環(huán)境下時(shí):

      ~/_pageStart.cshtml

      ~/sub/_pageStart.cshtml

      ~/sub/somepage.cshtml

      III:Web Pages 1.0脫離WebForms的啟動(dòng)原理

      首先Web Pages利用特性往本身程序集上與ASP.NET掛鉤

      // SourceFile: AssemblyInfo.cs(System.Web.WebPages.dll)  //AttributeClass: System.Web. PreApplicationStartMethodAttribute  //特性介紹:為ASP.NET 其他Provide提供擴(kuò)展  //參數(shù)1: ASP.NET Provide的類(lèi)型  //參數(shù)2:運(yùn)行的方法名  //Source:  [assembly: PreApplicationStartMethod(typeof(System.Web.WebPages.PreApplicationStartCode), "Start")] //Line: 15

      然后我們?cè)谶@里可以看到Web Pages的ASP.NET Provide是.Web.WebPages.PreApplicationStartCode

      啟動(dòng)方法是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; //設(shè)置Start方法已被調(diào)用         WebPageHttpHandler.RegisterExtension("cshtml");//注冊(cè)擴(kuò)展      WebPageHttpHandler.RegisterExtension("vbhtml");//注冊(cè)擴(kuò)展         // Turn off the string resource behavior which would not work in our simple base page      PageParser.EnableLongStringsAsResources = false;//優(yōu)化選項(xiàng)         DynamicModuleUtility.RegisterModule(typeof(WebPageHttpModule));//重點(diǎn)在這里了.~~注冊(cè)了一個(gè)WebPageHttpModule         ScopeStorage.CurrentProvider = new AspNetRequestScopeStorageProvider();      //ASP.NET Web Pages的RequestScopeStorageProvider  }

      IV:附錄:Global執(zhí)行順序

      當(dāng)WebApp開(kāi)始運(yùn)行時(shí)

      Application_Start

      Application_BeginRequest

      Application_AuthenticateRequest

      Session_Start

      當(dāng)WebApp終止運(yùn)行時(shí)

      Session_End

      Application_End

      當(dāng)一個(gè)Request入站時(shí)

      Application_BeginRequest

      Application_AuthenticateRequest 過(guò)后到達(dá)*.cshtml

      當(dāng)在*.cshtml throw new Exception();時(shí)

      Application_BeginRequest  Application_AuthenticateRequest  Application_Error(在throw處轉(zhuǎn)至,不會(huì)執(zhí)行*.cshtml的throw后的下文)  例:  @{  Throw new Exception();//僅做示例  //下文不會(huì)被執(zhí)行,而直接跳到Application_Error終止Response  }

      看完上述內(nèi)容,你們對(duì)如何理解ASP.NET MVC 中的Web Pages有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。


      分享題目:如何理解ASP.NETMVC中的WebPages
      文章地址:http://www.ef60e0e.cn/article/jehhho.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        西吉县| 化隆| 乌兰浩特市| 木兰县| 奉化市| 舒城县| 泰顺县| 荔浦县| 和顺县| 富川| 晋江市| 乌拉特后旗| 宁乡县| 甘谷县| 壤塘县| 页游| 武鸣县| 平凉市| 噶尔县| 财经| 福州市| 松桃| 河津市| 报价| 繁昌县| 沁阳市| 曲沃县| 青阳县| 延长县| 获嘉县| 淳化县| 新泰市| 鸡西市| 鄯善县| 永康市| 黑水县| 江达县| 黔东| 泸定县| 衡山县| 科技|