internal static WebPageRazorHost CreateHostFromConfigCore(RazorWebSectionGroup config, string virtualPath, string physicalPath)
        {
            // Use the virtual path to select a host environment for the generated code
            // Do this check here because the App_Code host can't be overridden.

            // Make the path app relative
            virtualPath = EnsureAppRelative(virtualPath);

            if (virtualPath.StartsWith("~/App_Code", StringComparison.OrdinalIgnoreCase))   // change to app-code
            // Under App_Code => It's a Web Code file
            {
                return(new WebCodeRazorHost(virtualPath, physicalPath));
            }

            WebRazorHostFactory factory = null;

            if (config != null && config.Host != null && !String.IsNullOrEmpty(config.Host.FactoryType))
            {
                Func <WebRazorHostFactory> factoryCreator = _factories.GetOrAdd(config.Host.FactoryType, CreateFactory);
                Debug.Assert(factoryCreator != null); // CreateFactory should throw if there's an error creating the factory
                factory = factoryCreator();
            }

            WebPageRazorHost host = (factory ?? new WebRazorHostFactory()).CreateHost(virtualPath, physicalPath);

            if (config != null && config.Pages != null)
            {
                ApplyConfigurationToHost(config.Pages, host);
            }

            return(host);
        }
Esempio n. 2
0
 protected internal virtual WebPageRazorHost CreateHost()
 {
     return(WebRazorHostFactory.CreateHostFromConfig(VirtualPath));
 }