如何修复 500.30 - ASP.NET CORE 应用程序无法启动

moh*_*imi 12 asp.net iis asp.net-core

在IIS上发布程序后,我们遇到了这个错误

HTTP Error 500.30 - ASP.NET Core app failed to start
Common solutions to this issue:
The app failed to start
The app started but then stopped
The app started but threw an exception during startup
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=2028265
Run Code Online (Sandbox Code Playgroud)

当我们检查 stdout 日志文件后,出现此错误

  at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at ArtanNet.Program.Main(String[] args) in C:\Users\Administrator\Desktop\ArtanNet\ArtanNet\Program.cs:line 16
Run Code Online (Sandbox Code Playgroud)

program.cs文件代码为:

 public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
Run Code Online (Sandbox Code Playgroud)

网络配置:

<?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=".\ArtanNet.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: d6cea5f9-6e6d-4f03-b6e9-1d0fb599d508-->
Run Code Online (Sandbox Code Playgroud)

现在请帮助我们修复这个错误

小智 13

HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动是一个非常通用的错误消息。

要获取更具体的异常消息,您必须设置 enable ASPNETCORE_DETAILEDERRORS。要在 Azure 门户中执行此操作,请按照以下步骤操作:

  1. 导航到 Azure 门户并打开您的应用服务应用程序。
  2. 在左侧菜单中,单击“配置”。
  3. 向下滚动到“应用程序设置”部分,然后单击“新应用程序设置”按钮。
  4. 在“名称”字段中,输入 ASPNETCORE_DETAILEDERRORS(不带引号)。
  5. 在“值”字段中,输入 true(不带引号)。
  6. 单击“确定”按钮保存设置。

现在,当您打开应用程序时,将显示详细的异常,而不是通用 HTTP 错误 500.30 - ASP.NET Core 应用程序无法启动。

  • 这节省了我很多时间。我在其他日志中看不到任何相关信息。启用详细错误后,我确切地了解了问题所在。就我而言,问题出在 Microsoft.Extensions.Logging 6.0.14 上。无论出于何种原因,它在用于暂存的订阅下的 Azure 应用服务中不可用。我在开发订阅中使用相同的应用程序没有任何问题。诡异的! (2认同)

小智 10

您使用的是哪个核心版本?您使用什么托管模型?进程内还是进程外?您可以在 csproj 文件中检查 thios 。如果您使用 In of Process,请尝试将其更改为

 <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考 - 根据 [MS doco](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/in-process-hosting?查看=aspnetcore-6.0)。“进程内托管比进程外托管提供了更高的性能,因为请求不是通过环回适配器代理的”。 (2认同)