internal static WebPageMatch MatchRequest(string pathValue, string[] supportedExtensions, Func<string, bool> virtualPathExists, HttpContextBase context, DisplayModeProvider displayModes)
{
string currentLevel = String.Empty;
string currentPathInfo = pathValue;
// We can skip the file exists check and normal lookup for empty paths, but we still need to look for default pages
if (!String.IsNullOrEmpty(pathValue))
{
// If the file exists and its not a supported extension, let the request go through
if (FileExists(pathValue, virtualPathExists))
{
// TODO: Look into switching to RawURL to eliminate the need for this issue
bool foundSupportedExtension = false;
for (int i = 0; i < supportedExtensions.Length; i++)
{
string supportedExtension = supportedExtensions[i];
if (PathHelpers.EndsWithExtension(pathValue, supportedExtension))
{
foundSupportedExtension = true;
break;
}
}
if (!foundSupportedExtension)
{
return null;
}
}
// For each trimmed part of the path try to add a known extension and
// check if it matches a file in the application.
currentLevel = pathValue;
currentPathInfo = String.Empty;
while (true)
{
// Does the current route level patch any supported extension?
string routeLevelMatch = GetRouteLevelMatch(currentLevel, supportedExtensions, virtualPathExists, context, displayModes);
if (routeLevelMatch != null)
{
return new WebPageMatch(routeLevelMatch, currentPathInfo);
}
// Try to remove the last path segment (e.g. go from /foo/bar to /foo)
int indexOfLastSlash = currentLevel.LastIndexOf('/');
if (indexOfLastSlash == -1)
{
// If there are no more slashes, we're done
break;
}
else
{
// Chop off the last path segment to get to the next one
currentLevel = currentLevel.Substring(0, indexOfLastSlash);
// And save the path info in case there is a match
currentPathInfo = pathValue.Substring(indexOfLastSlash + 1);
}
}
}
return MatchDefaultFiles(pathValue, supportedExtensions, virtualPathExists, context, displayModes, currentLevel);
}