【问题标题】:HTTP 500.19 Error for Dot Net 5.0 WebAPI Application [closed]Dotnet 5.0 Web API 应用程序的 HTTP 500.19 错误 [关闭]
【发布时间】:2021-04-22 03:31:38
【问题描述】:

我在自己的服务器上安装了 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-->

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

【问题讨论】:

标签: windows iis asp.net-web-api


【解决方案1】:

Publish Core 到 IIS 需要安装 .NET Core Hosting Bundle,有关它的更多信息,您可以参考这个link

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

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

【讨论】:

    【解决方案2】:

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

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

    需要设置的公共设置

    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,现在一切正常!

    【讨论】:

      猜你喜欢
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      相关资源
      最近更新 更多