我已经实现了自定义VirtualPathProvider来提供来自数据库的可自定义视图,当我在FileExists方法上放置一个断点时,我注意到该框架对我的项目提出了大量不必要的请求。例如,当我请求不存在的操作(例如http://localhost/Example/Action)时,框架会查找:
当我发出与添加的路线匹配的请求(例如http://localhost/Test)时,框架会查找:
甚至在初始化控制器之前。初始化控制器后,框架将查找我已实现的自定义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 :(得分:0)
他们可能与RouteCollection.RouteExistingFiles
财产有关吗?我检查大量文件而不仅仅是匹配的文件是没有意义的,但是可能值得关闭以查看它是否有任何区别。