zoukankan      html  css  js  c++  java
  • ASP.NET MVC学习(四)之视图View

    1.视图

    2.强类型视图

    3.@RenderSection("HeaderSection", false)     @RenderBody()

    4.子行为

    5.ASP.NET MVC载入页面常用方法

    http://www.cnblogs.com/baisoft/p/5839319.html

    @RenderBody

    @RenderPage

    @RenderSection

    @Html.Partial

    @RenderPage()和@RenderPartial()的区别

    @Html.RenderPartial和@Html.RenderAction的区别

    MVC中的一些特殊优化

    删除WebForm视图引擎

    在MVC框架中检索视图的顺序为:当前控制器下对应的文件夹的aspx文件→share文件夹aspx文件→当前控制器下对应文件夹的cshtml文件→share文件夹的cshtml文件。

       鉴于以上顺序,如果我们使用的MVC5框架中不需要WebForm的视图引擎,可以删除,来提高视图的检索速度。

       同样是在Global.asax中操作,代码如下:

    public class MvcApplication : System.Web.HttpApplication
        {
            /// <summary>
            /// 删除WebForm视图即aspx文件视图检索引擎
            /// </summary>
            protected void RemoveWebFormEngines()
            {
                var viewEngines = ViewEngines.Engines;
                var webFormEngines = viewEngines.OfType<WebFormViewEngine>().FirstOrDefault();
                if (webFormEngines != null)
                {
                    viewEngines.Remove(webFormEngines);
                }
            }
    
    
            /// <summary>
            /// 网站第一次启动的时候会率先执行,且只执行一次
            /// </summary>
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();  //区域
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  //过滤器
                RouteConfig.RegisterRoutes(RouteTable.Routes);   //常规路由
                BundleConfig.RegisterBundles(BundleTable.Bundles);   //js包、css包、combres
    
                //删除WebForm视图即aspx文件视图检索引擎
                RemoveWebFormEngines();
                //阻止MVC将版本号发回给浏览器
                MvcHandler.DisableMvcResponseHeader = true;
                //注册自定义实例化控制器的容器
                ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory());
            }
        }

    隐藏MVC版本号

    在Global.asax中的Application_Start()方法中添加一句话:MvcHandler.DisableMvcResponseHeader = true;  即可阻止将MVC版本暴露给浏览器

  • 相关阅读:
    Elasticsearch学习系列之介绍安装
    Python学习系列之文件操作
    Python学习系列之异常处理
    Python学习系列之装饰器
    windows 修改xhsell安全加密配置
    ipv6nginx错误
    zabbix 硬盘状态收集,制作表格
    申请免费ssl证书
    gitlab 搭建与迁移
    mogilefsdBUG mogilefsd[15624]: crash log: Modification of a read-only value attempted at /usr/local/share/perl5/Sys/Syscall.pm line 227
  • 原文地址:https://www.cnblogs.com/cnki/p/6108738.html
Copyright © 2011-2022 走看看