System.Web.WebPages.WebPageRoute.GetRouteLevelMatch C# (CSharp) Method

GetRouteLevelMatch() private static method

private static GetRouteLevelMatch ( string pathValue, string supportedExtensions, bool>.Func virtualPathExists, HttpContextBase context, System.Web.WebPages.DisplayModeProvider displayModeProvider ) : string
pathValue string
supportedExtensions string
virtualPathExists bool>.Func
context HttpContextBase
displayModeProvider System.Web.WebPages.DisplayModeProvider
return string
        private static string GetRouteLevelMatch(string pathValue, string[] supportedExtensions, Func<string, bool> virtualPathExists, HttpContextBase context, DisplayModeProvider displayModeProvider)
        {
            for (int i = 0; i < supportedExtensions.Length; i++)
            {
                string supportedExtension = supportedExtensions[i];

                // For performance, avoid multiple calls to String.Concat
                string virtualPath;
                // Only add the extension if it's not already there
                if (!PathHelpers.EndsWithExtension(pathValue, supportedExtension))
                {
                    virtualPath = "~/" + pathValue + "." + supportedExtension;
                }
                else
                {
                    virtualPath = "~/" + pathValue;
                }
                DisplayInfo virtualPathDisplayInfo = displayModeProvider.GetDisplayInfoForVirtualPath(virtualPath, context, virtualPathExists, currentDisplayMode: null);

                if (virtualPathDisplayInfo != null)
                {
                    // If there's an exact match on disk, return it unless it starts with an underscore
                    if (Path.GetFileName(virtualPathDisplayInfo.FilePath).StartsWith("_", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new HttpException(404, WebPageResources.WebPageRoute_UnderscoreBlocked);
                    }

                    string resolvedVirtualPath = virtualPathDisplayInfo.FilePath;

                    // Matches are not expected to be virtual paths so remove the ~/ from the match
                    if (resolvedVirtualPath.StartsWith("~/", StringComparison.OrdinalIgnoreCase))
                    {
                        resolvedVirtualPath = resolvedVirtualPath.Remove(0, 2);
                    }

                    DisplayModeProvider.SetDisplayMode(context, virtualPathDisplayInfo.DisplayMode);

                    return resolvedVirtualPath;
                }
            }

            return null;
        }