Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to create a WebPageBase instance from a virtualPath and wraps complex compiler exceptions with simpler messages
        /// </summary>
        protected virtual WebPageBase CreatePageFromVirtualPath(
            string virtualPath,
            HttpContextBase httpContext,
            Func <string, bool> virtualPathExists,
            DisplayModeProvider displayModeProvider,
            IDisplayMode displayMode
            )
        {
            try
            {
                DisplayInfo resolvedDisplayInfo = displayModeProvider.GetDisplayInfoForVirtualPath(
                    virtualPath,
                    httpContext,
                    virtualPathExists,
                    displayMode
                    );

                if (resolvedDisplayInfo != null)
                {
                    var webPage = VirtualPathFactory.CreateInstance <WebPageBase>(
                        resolvedDisplayInfo.FilePath
                        );

                    if (webPage != null)
                    {
                        // Give it its virtual path
                        webPage.VirtualPath         = virtualPath;
                        webPage.VirtualPathFactory  = VirtualPathFactory;
                        webPage.DisplayModeProvider = DisplayModeProvider;

                        return(webPage);
                    }
                }
            }
            catch (HttpException e)
            {
                // If the path uses an unregistered extension, such as Foo.txt,
                // then an error regarding build providers will be thrown.
                // Check if this is the case and throw a simpler error.
                BuildManagerExceptionUtil.ThrowIfUnsupportedExtension(virtualPath, e);

                // If the path uses an extension registered with codedom, such as Foo.js,
                // then an unfriendly compilation error might get thrown by the underlying compiler.
                // Check if this is the case and throw a simpler error.
                BuildManagerExceptionUtil.ThrowIfCodeDomDefinedExtension(virtualPath, e);

                // Rethrow any errors
                throw;
            }
            // The page is missing, could not be compiled or is of an invalid type.
            throw new HttpException(
                      String.Format(
                          CultureInfo.CurrentCulture,
                          WebPageResources.WebPage_InvalidPageType,
                          virtualPath
                          )
                      );
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private static string GetRouteLevelMatch(string pathValue, IEnumerable <string> supportedExtensions, IVirtualPathFactory virtualPathFactory, HttpContextBase context, DisplayModeProvider displayModeProvider)
        {
            foreach (string supportedExtension in supportedExtensions)
            {
                string virtualPath = "~/" + pathValue;

                // Only add the extension if it's not already there
                if (!virtualPath.EndsWith("." + supportedExtension, StringComparison.OrdinalIgnoreCase))
                {
                    virtualPath += "." + supportedExtension;
                }
                DisplayInfo virtualPathDisplayInfo = displayModeProvider.GetDisplayInfoForVirtualPath(virtualPath, context, virtualPathFactory.Exists, 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);
        }
Ejemplo n.º 4
0
        protected virtual string GetPathFromGeneralName(ControllerContext controllerContext, List <ThemeableVirtualPathProviderViewEngine.ViewLocation> locations, string name, string controllerName, string areaName, string cacheKey, ref string[] searchedLocations)
        {
            Func <string, bool> func;
            Func <string, bool> func1 = null;
            Func <string, bool> func2 = null;
            string empty = string.Empty;

            searchedLocations = new string[locations.Count];
            int num = 0;

            while (num < locations.Count)
            {
                ThemeableVirtualPathProviderViewEngine.ViewLocation item = locations[num];
                string str = "";
                str = item.Format(name, controllerName, areaName);
                if (!File.Exists(HttpContext.Current.Server.MapPath(str)))
                {
                    str = item.Format(name, controllerName, areaName);
                }
                System.Web.WebPages.DisplayModeProvider displayModeProvider = base.DisplayModeProvider;
                string              str1        = str;
                HttpContextBase     httpContext = controllerContext.HttpContext;
                Func <string, bool> func3       = func1;
                if (func3 == null)
                {
                    Func <string, bool> func4 = (string path) => this.FileExists(controllerContext, path);
                    func  = func4;
                    func1 = func4;
                    func3 = func;
                }
                DisplayInfo displayInfoForVirtualPath = displayModeProvider.GetDisplayInfoForVirtualPath(str1, httpContext, func3, controllerContext.DisplayMode);
                if (displayInfoForVirtualPath == null)
                {
                    searchedLocations[num] = str;
                    num++;
                }
                else
                {
                    string filePath = displayInfoForVirtualPath.FilePath;
                    searchedLocations = ThemeableVirtualPathProviderViewEngine._emptyLocations;
                    empty             = filePath;
                    base.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, this.AppendDisplayModeToCacheKey(cacheKey, displayInfoForVirtualPath.DisplayMode.DisplayModeId), empty);
                    if (controllerContext.DisplayMode == null)
                    {
                        controllerContext.DisplayMode = displayInfoForVirtualPath.DisplayMode;
                    }
                    foreach (IDisplayMode mode in base.DisplayModeProvider.Modes)
                    {
                        if (mode.DisplayModeId != displayInfoForVirtualPath.DisplayMode.DisplayModeId)
                        {
                            IDisplayMode        displayMode     = mode;
                            HttpContextBase     httpContextBase = controllerContext.HttpContext;
                            string              str2            = str;
                            Func <string, bool> func5           = func2;
                            if (func5 == null)
                            {
                                Func <string, bool> func6 = (string path) => this.FileExists(controllerContext, path);
                                func  = func6;
                                func2 = func6;
                                func5 = func;
                            }
                            DisplayInfo displayInfo = displayMode.GetDisplayInfo(httpContextBase, str2, func5);
                            string      empty1      = string.Empty;
                            if ((displayInfo == null ? false : displayInfo.FilePath != null))
                            {
                                empty1 = displayInfo.FilePath;
                            }
                            base.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, this.AppendDisplayModeToCacheKey(cacheKey, mode.DisplayModeId), empty1);
                        }
                    }
                    break;
                }
            }
            return(empty);
        }
Ejemplo n.º 5
0
 private WebPageBase CreatePageFromVirtualPath(string virtualPath, HttpContextBase httpContext, Func<string, bool> virtualPathExists, DisplayModeProvider displayModeProvider, IDisplayMode displayMode)
 {
     try
       {
     DisplayInfo infoForVirtualPath = displayModeProvider.GetDisplayInfoForVirtualPath(virtualPath, httpContext, virtualPathExists, displayMode);
     if (infoForVirtualPath != null)
     {
       WebPageBase instance = VirtualPathFactoryExtensions.CreateInstance<WebPageBase>(this.VirtualPathFactory, infoForVirtualPath.FilePath);
       if (instance != null)
       {
     instance.VirtualPath = virtualPath;
     instance.VirtualPathFactory = this.VirtualPathFactory;
     instance.DisplayModeProvider = this.DisplayModeProvider;
     return instance;
       }
     }
       }
       catch (HttpException ex)
       {
     BuildManagerExceptionUtil.ThrowIfUnsupportedExtension(virtualPath, ex);
     BuildManagerExceptionUtil.ThrowIfCodeDomDefinedExtension(virtualPath, ex);
     throw;
       }
       throw new HttpException(string.Format((IFormatProvider) CultureInfo.CurrentCulture, WebPageResources.WebPage_InvalidPageType, new object[1]
       {
     (object) virtualPath
       }));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to create a WebPageBase instance from a virtualPath and wraps complex compiler exceptions with simpler messages
        /// </summary>
        private WebPageBase CreatePageFromVirtualPath(string virtualPath, HttpContextBase httpContext, Func<string, bool> virtualPathExists, DisplayModeProvider displayModeProvider, IDisplayMode displayMode)
        {
            try
            {
                DisplayInfo resolvedDisplayInfo = displayModeProvider.GetDisplayInfoForVirtualPath(virtualPath, httpContext, virtualPathExists, displayMode);

                if (resolvedDisplayInfo != null)
                {
                    var webPage = VirtualPathFactory.CreateInstance<WebPageBase>(resolvedDisplayInfo.FilePath);

                    if (webPage != null)
                    {
                        // Give it its virtual path
                        webPage.VirtualPath = virtualPath;
                        webPage.VirtualPathFactory = VirtualPathFactory;
                        webPage.DisplayModeProvider = DisplayModeProvider;

                        return webPage;
                    }
                }
            }
            catch (HttpException e)
            {
                // If the path uses an unregistered extension, such as Foo.txt,
                // then an error regarding build providers will be thrown.
                // Check if this is the case and throw a simpler error.
                BuildManagerExceptionUtil.ThrowIfUnsupportedExtension(virtualPath, e);

                // If the path uses an extension registered with codedom, such as Foo.js,
                // then an unfriendly compilation error might get thrown by the underlying compiler.
                // Check if this is the case and throw a simpler error.
                BuildManagerExceptionUtil.ThrowIfCodeDomDefinedExtension(virtualPath, e);

                // Rethrow any errors
                throw;
            }
            // The page is missing, could not be compiled or is of an invalid type.
            throw new HttpException(String.Format(CultureInfo.CurrentCulture, WebPageResources.WebPage_InvalidPageType, virtualPath));
        }
Ejemplo n.º 7
0
        private static string GetRouteLevelMatch(string pathValue, IEnumerable<string> supportedExtensions, IVirtualPathFactory virtualPathFactory, HttpContextBase context, DisplayModeProvider displayModeProvider)
        {
            foreach (string supportedExtension in supportedExtensions)
            {
                string virtualPath = "~/" + pathValue;

                // Only add the extension if it's not already there
                if (!virtualPath.EndsWith("." + supportedExtension, StringComparison.OrdinalIgnoreCase))
                {
                    virtualPath += "." + supportedExtension;
                }
                DisplayInfo virtualPathDisplayInfo = displayModeProvider.GetDisplayInfoForVirtualPath(virtualPath, context, virtualPathFactory.Exists, 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;
        }
Ejemplo n.º 8
0
        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;
        }