/*
         * Compile a template control (aspx or ascx) file and return its Type
         */
        private Type GetReferencedType(TemplateControlParser parser, string virtualPath)
        {
            // Make sure the page is never treated as a Trivial Page (ASURT bugs 8903,42166,73887)
            parser._fAlwaysCompile = true;

            string fullVirtualPath = UrlPath.Combine(BaseVirtualDir, virtualPath);

            parser.InputFile = MapPath(fullVirtualPath, false /*allowCrossAppMapping*/);

            parser.CurrentVirtualPath = fullVirtualPath; // To get correct config settings

            parser.Context = Context;
            parser._circularReferenceChecker = _circularReferenceChecker; // To fix ASURT 30990

            // Perform the compilation
            ParserCacheItem cacheItem = parser.GetParserCacheItemWithNewConfigPath();

            Debug.Assert(cacheItem.type != null);

            // Add a dependency on the created Type
            AddTypeDependency(cacheItem.type);

            // Add a dependency on the cache sources used to cache the created Type
            AddSourceDependencies(parser.SourceDependencies);

            return(cacheItem.type);
        }
        internal Type GetCompiledType(string virtualPath,
                                      string inputFile, HttpContext context)
        {
            ParserCacheItem cacheItem = CompileAndGetParserCacheItem(virtualPath,
                                                                     inputFile, context);

            return(cacheItem.type);
        }
        /*
         * Compile an .aspx file into an HttpApplication Type
         */
        internal static Type GetCompiledApplicationType(string inputFile, HttpContext context,
                                                        out ApplicationFileParser parser)
        {
            parser = new ApplicationFileParser();
            parser.CurrentVirtualPath = UrlPath.Combine(context.Request.ApplicationPath,
                                                        HttpApplicationFactory.applicationFileName);
            parser.InputFile = inputFile;
            parser.Context   = context;

            // Never use trivial pages for global.asax (ASURT 32420)
            parser._fAlwaysCompile = true;

            ParserCacheItem cacheItem = parser.GetParserCacheItem();

            Debug.Assert(cacheItem.type != null);
            return(cacheItem.type);
        }
        internal object GetCompiledInstance(string virtualPath,
                                            string inputFile, HttpContext context)
        {
            ParserCacheItem cacheItem = CompileAndGetParserCacheItem(virtualPath,
                                                                     inputFile, context);

            // Instantiate the object
            object ob = null;

            try {
                if (cacheItem.trivialPageContent != null)
                {
                    Debug.Assert(cacheItem.type == null);
                    ob = new TrivialPage(cacheItem.trivialPageContent);
                }
                else
                {
                    // impersonate client while executing page ctor (see 89712)
                    // (compilation is done while not impersonating client)
                    context.Impersonation.ReimpersonateIfSuspended();

                    try {
                        ob = HttpRuntime.CreatePublicInstance(cacheItem.type);
                    }
                    finally {
                        context.Impersonation.StopReimpersonation();
                    }
                }
            }
            catch (Exception e) {
                throw new HttpException(HttpRuntime.FormatResourceString(
                                            SR.Failed_to_create_page_of_type, cacheItem.type.FullName), e);
            }

            return(ob);
        }