2011-09-24 74 views
1

我已經實現了自定義的VirtualPathProvider來爲數據庫提供可定製視圖,並且當我在FileExists方法上放置一個斷點時,我注意到該框架對許多不必要的(對於我的項目)請求。例如,當我爲不存在的動作的請求(例如http://localhost/Example/Action)的框架查找:可以重新配置MVC路由解析機制嗎?

  • 「〜/實施例/動作/ 5」
  • 「〜/實施例/動作/ 5.cshtml」
  • 「〜/實施例/動作/ 5.vbhtml」
  • 「〜/實施例/ Action.cshtml」
  • 「〜/實施例/ Action.vbhtml」
  • 「〜/ Example.cshtml」
  • 「〜/ Example.vbhtml」
  • 「〜/實施例/動作/ 5/default.cshtml」
  • 「〜/實施例/動作/ 5/default.vbhtml」
  • 「〜/實施例/動作/ 5/index.cshtml」
  • 「〜/實施例/動作/ 5/index.vbhtml」
  • 「〜/ favicon.ico的」
  • 「〜/ favicon.ico.cshtml」
  • 「〜/ favicon.ico.vb​​html」
  • 「〜/ favicon.ico/default.cshtml」
  • 「〜/ favicon.ico/default.vbhtml」
  • 「〜/的favicon.ico/index.cshtml」
  • 「〜/的favicon.ico/index.vbhtml」

當我作出這樣的匹配的添加的路由的請求(例如http://localhost/Test)的框架尋找:

  • 「〜/測試」
  • 「〜/ Test.cshtml」
  • 「〜/ Test.vbhtml」
  • 「〜/測試/ DEF ault.cshtml」
  • 「〜/測試/ default.vbhtml」
  • 「〜/測試/ index.cshtml」
  • 「〜/測試/ index.vbhtml」

即使在初始化之前控制器。控制器初始化後,框架會查找我已經實現的自定義RazorViewEngine中定義的視圖。

這是我的ViewEngine

 AreaViewLocationFormats = new string[] { }; 
     AreaMasterLocationFormats = new string[] { }; 
     AreaPartialViewLocationFormats = new string[] { }; 
     MasterLocationFormats = new string[] { }; 
     ViewLocationFormats = new string[] { 
      "~/Views/Dynamic/{1}/{0}.cshtml", 
      "~/Views/Dynamic/Shared/{0}.cshtml", 
      "~/Views/{1}/{0}.cshtml", 
      "~/Views/Shared/{0}.cshtml" 
     }; 
     PartialViewLocationFormats = new string[] { 
      "~/Views/Dynamic/{1}/Partial/{0}.cshtml", 
      "~/Views/Dynamic/Shared/Partial/{0}.cshtml", 
      "~/Views/{1}/Partial/{0}.cshtml", 
      "~/Views/Shared/Partial/{0}.cshtml" 
     }; 
     FileExtensions = new string[] { "cshtml" }; 

所以,問題是可以將這些默認路由被刪除,怎麼樣?

回答

0

它們可能與RouteCollection.RouteExistingFiles屬性有關嗎?我沒有理由檢查大量的文件,而不是僅僅匹配一個文件,但可能需要關閉以查看是否有任何區別。