Exemple #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
                          )
                      );
        }
Exemple #2
0
        internal static WebPageBase CreateInstanceFromVirtualPath(string virtualPath, IVirtualPathFactory virtualPathFactory)
        {
            // Get the compiled object
            try
            {
                WebPageBase webPage = virtualPathFactory.CreateInstance <WebPageBase>(virtualPath);

                // Give it its virtual path
                webPage.VirtualPath = virtualPath;

                // Assign it the VirtualPathFactory
                webPage.VirtualPathFactory = virtualPathFactory;

                return(webPage);
            }
            catch (HttpException e)
            {
                BuildManagerExceptionUtil.ThrowIfUnsupportedExtension(virtualPath, e);
                throw;
            }
        }