HTTP 错误 500.19 - 内部服务器错误代码 0x8007000d

HTTP Error 500.19 - internal server error code 0x8007000d

我创建了一个 ASP.NET Core 5.0 Web API 项目。我可以在 IIS Express 中执行和 运行 应用程序。如果我部署应用程序,则会收到以下错误:

Server Error in Application "application name"
HTTP Error 500.19 – Internal Server Error
HRESULT: 0x8007000d
Description of HRESULT
The requested page cannot be accessed because the related configuration data for the page is invalid.

官方MS support page引用了两个原因:

This problem occurs because the ApplicationHost.config or Web.config file contains a malformed or unidentified XML element. IIS can't identify the XML elements of the modules that are not installed. For example, IIS URL Rewrite module.

Resolution

Use one of the following methods:

Delete the malformed XML element from the ApplicationHost.config or Web.config file.
Check the unidentified XML elements, and then install the relevant IIS modules.

我安装了 IIS URL 重写模块没有效果。

我的 web.config 带有我的 build/deploy 过程。对于配置,我使用 appsettings.json。所以我不知道我的 web.config 中是否有可能发生变化以及发生了什么变化。有什么建议吗?

...\inetpub\wwwroot\MyApi\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=".\MyApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: f659debd-cac7-4ce5-b2fe-d1a440a87811-->

您应该安装托管包版本的 .Net 以在服务器上的 IIS 中添加对 .Net 核心运行时的支持

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-5.0.13-windows-hosting-bundle-installer

所有下载: https://dotnet.microsoft.com/en-us/download/dotnet/5.0