DB からカスタマイズ可能なビューを提供するカスタム VirtualPathProvider を実装しました。FileExists メソッドにブレークポイントを設定すると、フレームワークが (私のプロジェクトにとって) 不要な要求を大量に実行することに気付きました。たとえば、存在しないアクション (例: http://localhost/Example/Action ) をリクエストすると、フレームワークは次を探します。
- 「~/例/アクション/5」
- 「~/例/アクション/5.cshtml」
- 「~/例/アクション/5.vbhtml」
- 「~/例/Action.cshtml」
- 「~/例/Action.vbhtml」
- 「~/Example.cshtml」
- 「~/Example.vbhtml」
- 「~/Example/Action/5/default.cshtml」
- 「~/Example/Action/5/default.vbhtml」
- 「~/Example/Action/5/index.cshtml」
- 「~/Example/Action/5/index.vbhtml」
- 「~/favicon.ico」
- 「~/favicon.ico.cshtml」
- 「~/favicon.ico.vbhtml」
- "~/favicon.ico/default.cshtml"
- "~/favicon.ico/default.vbhtml"
- 「~/favicon.ico/index.cshtml」
- "~/favicon.ico/index.vbhtml"
追加されたルート ( http://localhost/Testなど) に一致するリクエストを行うと、フレームワークは次を探します。
- 「~/テスト」
- 「~/Test.cshtml」
- 「~/Test.vbhtml」
- 「~/Test/default.cshtml」
- 「~/Test/default.vbhtml」
- 「~/Test/index.cshtml」
- 「~/Test/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" };
問題は、これらのデフォルト ルートを削除する方法と、その方法です。