Beispiel #1
0
        internal static void EnsureValidPageType(WebPageBase page, string virtualPath)
        {
            bool error = true;

            try {
                if (page.FileExists(virtualPath))
                {
                    var factory = page.GetObjectFactory(virtualPath);
                    if (factory != null)
                    {
                        var result = factory();
                        if (result != null && typeof(WebPageBase).IsAssignableFrom(result.GetType()))
                        {
                            error = false;
                        }
                    }
                }
            }
            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.
                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.
                ThrowIfCodeDomDefinedExtension(virtualPath, e);

                // Rethrow any errors
                throw;
            }

            if (error)
            {
                // 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));
            }
        }