我创建了一个ASP.NET Core 5.0 Web API项目。我可以在IIS Express中执行和运行应用程序。如果我部署应用程序,那么我会收到以下错误提示:
...\inetpub\wwwroot\MyApi\web.config:
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.
官方 微软支持页面 引用了两个原因:
我安装了IIS URL Rewrite模块,但没有生效。 我的web.config是通过构建/部署过程生成的。对于配置,我使用appsettings.json。所以我不知道我的web.config需要更改什么。有什么建议吗?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.
...\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-->