1

我正在加载一个在 IIS7 和 IIS6 中使用 BlogEngine4 构建的博客,我已经完成了所有配置,并在 Google 的帮助下通过所有可能性缩小了问题范围。但我最终得到以下错误。谁有聪明的答案?

所有页面都加载正常,但仅当我加载 .cshtml 文件页面未加载时

“/blog”应用程序中的服务器错误。

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines 

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.InvalidOperationException: Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines

源错误:

在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

Stack Trace: 
[InvalidOperationException: Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines]
System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(String typeName) +178
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +64System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup config, String virtualPath, String physicalPath) +201
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath, String physicalPath) +41
System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath) +7
System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig() +16
System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +17
System.Web.WebPages.Razor.RazorBuildProvider.get_Host() +21
System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode() +66
System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType() +39
System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +94
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +207
System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +41
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +658
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +360
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +107
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +96
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp) +13
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +45
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +23
System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +228
System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +147
System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +192
System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +74
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +24
System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath) +20
System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context) +250
System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +94
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +135
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +168

版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.272

4

1 回答 1

1

如果您尝试在 Umbraco 站点的虚拟目录中托管 blogengine 站点,则必须修改 blogengine web.config 以“删除”所有 Umbraco 特定的处理程序和模块,因为这些将由 blogengine 继承应用程序,导致此异常,因为应用程序在其 bin 文件夹中找不到相关的 DLL。

我最近遇到了类似的问题,我已经在下面的虚拟目录中发布了我使用的 web.config。我的是一个非常简单的 Web 应用程序,所以显然这在您的 blogengine 应用程序中不会单独工作。您需要将相关部分添加到您的 web.config 文件中。

此外,这是在 IIS7.5 中安装的 v6 Umbraco,因此您可能需要进行一些试验。

<?xml version="1.0"?>

<configuration>
  <configSections>
    <remove name="urlrewritingnet" />
    <remove name="umbraco.presentation.Properties.Settings" />
    <remove name="clientDependency" />
    <remove name="Examine" />
    <remove name="ExamineLuceneIndexSets" />
    <remove name="FileSystemProviders"  />
    <remove name="log4net" />
    <remove name="BaseRestExtensions" />
    <remove name="system.web.webPages.razor" />
  </configSections>

  <appSettings>
    <clear/>
  </appSettings>

  <system.web>
    <httpModules>
      <remove name="UrlRewriteModule" />
      <remove name="UmbracoModule" />
      <remove name="ClientDependencyModule" />
    </httpModules>
    <httpHandlers>
      <remove verb="*" path="umbraco/channels.aspx" />
      <remove verb="*" path="umbraco/channels/word.aspx" />
      <remove verb="*" path="DependencyHandler.axd" />
      <remove verb="GET,HEAD,POST" path="GoogleSpellChecker.ashx" />
    </httpHandlers>    
    <compilation defaultLanguage="c#" debug="false" batch="false" targetFramework="4.0">
      <buildProviders>
        <remove extension=".cshtml" />
        <remove extension=".vbhtml" />
        <remove extension=".razor" />
      </buildProviders>
    </compilation>
    <membership>
      <providers>
        <remove name="UmbracoMembershipProvider" />
        <remove name="UsersMembershipProvider" />
      </providers>
    </membership>
    <!-- added by NH to support membership providers in access layer -->
    <roleManager enabled="false">
      <providers>
        <remove name="UmbracoRoleProvider" />
      </providers>
    </roleManager>
    <!-- Sitemap provider-->
    <siteMap defaultProvider="UmbracoSiteMapProvider" enabled="false">
      <providers>
        <remove name="UmbracoSiteMapProvider" />
      </providers>
    </siteMap>

  </system.web>

  <system.webServer>
    <modules>
      <remove name="UrlRewriteModule" />
      <remove name="UmbracoModule" />
      <remove name="ClientDependencyModule" />
    </modules>
    <handlers accessPolicy="Read, Write, Script, Execute">
      <remove name="Channels" />
      <remove name="Channels_Word" />
      <remove name="ClientDependency" />
      <remove name="SpellChecker" />
    </handlers>
  </system.webServer>

</configuration>

更新:

<system.web.webPages.razor>如果您的应用程序 web.config 中存在该部分,则可能还需要更新该部分,将hostpages条目更改回其默认值:

<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory,
    System.Web.WebPages.Razor" />
<pages pageBaseType="System.Web.WebPages.WebPage">

这是因为 Umbraco 实现了它自己的主机工厂和页面库。

于 2013-07-20T14:01:42.850 回答