1

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.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」
  • 「~/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" };

問題は、これらのデフォルト ルートを削除する方法と、その方法です。

4

1 に答える 1

0

それらはRouteCollection.RouteExistingFilesプロパティに関連している可能性がありますか?一致するファイルだけでなく、多くのファイルをチェックするのは意味がありませんが、違いがあるかどうかを確認するためにオフにする価値があるかもしれません。

于 2011-10-06T20:28:24.347 に答える