Dot Net 5.0 WebAPI 应用程序的 HTTP 500.19 错误

HTTP 500.19 Error for Dot Net 5.0 WebAPI Application

我在我的服务器上安装了 WebAPI,但在浏览它时总是出现以下错误:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

我使用 Dot Net 5.0 WebAPI 进行设置,并在发布到目录后将其安装在最新版本的 IIS 中。

这是我的 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=".\akmazio-api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 3b944703-a011-4408-9581-8c919ba4ed0e-->

关于可能导致此问题的原因以及如何解决它的任何想法?

Publish Core to IIS 需要安装.NET Core Hosting Bundle,更多信息请参考link.

如果您已经按照上述步骤安装了.NET Core host bundle,但是这个问题还是没有解决。我建议你尝试部署一个核心模板应用程序,我怀疑你的应用程序可能有问题。

此外,您还可以使用FRT来解决这个问题。

看起来需要安装 .NET Core Hosting Bundle,需要修改应用程序以便通过注释掉 Startup.cs [=14] 中的 env.IsDevelopment() if 语句使 Swagger 正常工作=]函数,需要在Startup.csConfigure()函数中加入:

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

public 设置需要设置为

Target location: C:\publish\directory
Delete existing files: true
Configuration: Release
Target Framework: net5.0
Target Runtime: win-x64
Deployment Mode: Self-Contained

并且需要配置 IIS,以便应用程序池没有托管代码并使用网络服务运行。

瞧,我去 http:///localhost/swagger/index.html 现在一切正常!