码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-09-01 00:25:42      阅读:189      评论:0      收藏:0      [点我收藏+]

标签: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初始化顺序为: bubuko.com,布布扣 
(不排除本人未能发现的其他文件类型,但目前据我所知道应用最广的就这三个)

在Web Pages 1.0下,除非你显式以”_”开头命名View.否则你在请求”_”开头的页面时会遇到以下无法服务的页面提示
bubuko.com,布布扣 (这图在Razor语法基础时就帖过了.这里帖出来是让大家温故而知新)

关于*.cshtml生成的类名格式 绝大部分页生成的程序集格式 bubuko.com,布布扣 
页面编译都是以单独页面编译为单个带随机字符串的程序集,当然也可以采用预编译方式将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

标签:des   style   blog   http   color   os   io   strong   ar   

原文地址:http://www.cnblogs.com/mmcmmc/p/3948437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!