1

我已经实现了自定义 VirtualPathProvider 以从数据库中提供可自定义的视图,当我在 FileExists 方法上放置一个断点时,我注意到该框架执行了大量不必要的(对于我的项目)请求。例如,当我请求不存在的操作(例如http://localhost/Example/Action)时,框架会查找:

  • “~/示例/动作/5”
  • “~/Example/Action/5.cshtml”
  • “~/Example/Action/5.vbhtml”
  • “~/Example/Action.cshtml”
  • “~/Example/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 中定义的视图。

这是我的视图引擎

        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 回答