问题描述
我刚刚将我的 ASP.NET Core 2.2版迁移到了 ASP.NET Core 3.1版 。我已将网站配置为在IIS 进行中模式下运行。该应用程序在 IIS Express 托管的本地运行。
在最终测试期间,我部署到了我们的 IIS版本10 Web服务器上托管的测试站点。和以前一样,该站点按预期运行。今天,我将相同的构建部署到生产网站上,并在同一IIS服务器上运行,并不断收到以下错误:
HTTP Error 500.30 - ANCM In-Process Start Failure
我首先想到的是,两个网站之间的应用程序池配置必须有所不同,或者两个应用程序池标识之间的权限可能有所不同,但是目视检查显示这两个站点具有相同的配置-唯一我可以看到的区别是网站绑定是指向两个不同的URL的。
然后我想知道两个文件安装之间是否存在差异,因此我手动删除了生产站点的内容并从暂存站点复制了文件。这没什么区别,并且 ANCM进程内启动失败仍然存在。
我在IIS日志中看不到任何异常,但是如果查看Windows事件日志,则会看到一条错误消息:
Unable to access appsettings.json in C:\Windows\System32
我无法在线找到对此错误的任何引用,但是似乎出于某种原因,它没有引用C:\WWW\Reporting
的安装文件夹,而是默认为服务器的Windows文件夹。我怀疑这是线索,但是我不知道在哪里解决。
如果我更新web-config
文件并将托管模型更改为'OutOfProcess',则网站将正常运行。
摘要
相同的 ASP.NET Core版本3.1 网站的两个精确副本,安装在同一Web服务器上彼此相邻的目录中使用相同的IIS实例,一个站点正确运行,另一个站点错误为ANCM In-Process Start Failure
HTTP错误。
从Windows事件日志中,该站点似乎正在尝试从C:\Windows\System32
文件夹而不是其已安装的IIS Web文件夹开始。
代码段
Reporting.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TypeScriptToolsversion>Latest</TypeScriptToolsversion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<NeutralLanguage>en-GB</NeutralLanguage>
</PropertyGroup>
</Project>
Program.cs
var config = ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json",false,true)
.AddJsonFile($"appsettings.{env}.json",true)
.Build();
var webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIIS()
.UseStartup<Startup>()
.UseConfiguration(configuration);
webHost.Build().Run();
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore"
path="*"
verb="*"
modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processpath="dotnet"
arguments=".\Reporting.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
更新
Windows事件日志报告以下错误:
Application '/LM/W3SVC/106/ROOT' with physical root 'C:\www\Reporting\' hit unexpected managed exception,exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'c:\windows\system32\inetsrv\appsettings.json'.
这看起来很奇怪,因为我期望应用程序从应用程序的根目录('C:\ www \ Reporting')加载appsettings.json
文件
解决方法
最后,通常情况下,解决方案很简单,但是我在部署文档中却错过了它。
至少以我而言,运行out-of-process
的2.2版本仅需要直接对已安装的 Read 权限。在运行in-process
的3.1版本中,只需将应用程序权限增加到 读取并执行 。
我希望对其他错过此配置更改的人有所帮助。