一. 刪除WebForm視圖引擎css
在MVC框架中檢索視圖的順序爲:當前控制器下對應的文件夾的aspx文件→share文件夾aspx文件→當前控制器下對應文件夾的cshtml文件→share文件夾的cshtml文件。html
鑑於以上順序,若是咱們使用的MVC5框架中不須要WebForm的視圖引擎,能夠刪除,來提升視圖的檢索速度。web
一樣是在Global.asax中操做,代碼以下:瀏覽器
1 public class MvcApplication : System.Web.HttpApplication 2 { 3 /// <summary> 4 /// 刪除WebForm視圖即aspx文件視圖檢索引擎 5 /// </summary> 6 protected void RemoveWebFormEngines() 7 { 8 var viewEngines = ViewEngines.Engines; 9 var webFormEngines = viewEngines.OfType<WebFormViewEngine>().FirstOrDefault(); 10 if (webFormEngines != null) 11 { 12 viewEngines.Remove(webFormEngines); 13 } 14 } 15 16 17 /// <summary> 18 /// 網站第一次啓動的時候會率先執行,且只執行一次 19 /// </summary> 20 protected void Application_Start() 21 { 22 AreaRegistration.RegisterAllAreas(); //區域 23 FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); //過濾器 24 RouteConfig.RegisterRoutes(RouteTable.Routes); //常規路由 25 BundleConfig.RegisterBundles(BundleTable.Bundles); //js包、css包、combres 26 27 //刪除WebForm視圖即aspx文件視圖檢索引擎 28 RemoveWebFormEngines(); 29 //阻止MVC將版本號發回給瀏覽器 30 MvcHandler.DisableMvcResponseHeader = true; 31 //註冊自定義實例化控制器的容器 32 ControllerBuilder.Current.SetControllerFactory(new UnityControllerFactory()); 33 } 34 }
二. 隱藏MVC版本號框架
在Asp.Net MVC框架中,默認打開一個頁面,會將MVC的版本顯示在瀏覽器上,以下:網站
在Global.asax中的Application_Start()方法中添加一句話:MvcHandler.DisableMvcResponseHeader = true; 便可阻止將MVC版本暴露給瀏覽器,以下:ui