I have implemented custom VirtualPathProvider to serve customizable Views from a DB and when i put a breakpoint on the FileExists method I noticed that the framework does ton of unnecessary (for my project) requests. For example when I make a request for non-existing action (e.g. http://localhost/Example/Action) the framework looks for:
- "~/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.vbhtml"
- "~/favicon.ico/default.cshtml"
- "~/favicon.ico/default.vbhtml"
- "~/favicon.ico/index.cshtml"
- "~/favicon.ico/index.vbhtml"
When I make a request that matches an added route (e.g http://localhost/Test) the framework looks for:
- "~/Test"
- "~/Test.cshtml"
- "~/Test.vbhtml"
- "~/Test/default.cshtml"
- "~/Test/default.vbhtml"
- "~/Test/index.cshtml"
- "~/Test/index.vbhtml"
before even initialising the controller. After the controller is initialised the framework looks for the view as defined in the custom RazorViewEngine that I have implemented.
This is my 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" };
So the question is can these default routes be removed and how?