web.config 在服务器上发布我的 Core 2.2 项目后无效

web.config is invalid after publishing my Core 2.2 project on the server

我有一个在 Asp.NET Core 2.2 框架之上使用 C# 编写的项目。

我能够将它发布到我的 VPS。但是,当我尝试访问该网站时,出现以下错误

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

这是位于根

中的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=".\ProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 47b26df0-8a01-4d75-9549-3a98654550a3-->

web.config 文件与我的其他文件一起通过 Visual Studio 发布。但是我在我的解决方案中没有看到 web.config 文件。

此文件似乎无效。如何修复 web.config 文件?

如果我删除 web.config 文件并添加 index.html 页面,站点将正常工作。在我看来 web.config 文件由于某种原因无效。

已更新 我可以使用命令行 运行 应用程序。 使用命令行,我做了以下操作

  1. 我将目录更改为我网站的根目录(即 cd C:\inetpub\wwwroot\ProjectName
  2. 我执行以下命令dotnet ProjectName.dll
  3. 10 秒后,我得到了一些信息,表明该应用正在 运行ning,它向我显示了它正在列出的 URL。在我的例子中是 http://localhost:5000
  4. O 使用浏览器对浏览器 http://localhost:5000 并且工作正常。

但是当我使用域名访问它时,我仍然得到如上所述的Http Error 500.19。

如评论所述

在iis中安装AspnetCore模块

在您的环境中将 ASPNETCORE_ENVIRONMENT 设置为生产环境或 在 web.config.

中设置
<aspNetCore processPath="dotnet"
      arguments=".\MyApp.dll"
      stdoutLogEnabled="false"
      stdoutLogFile="\?\%home%\LogFiles\stdout"
      hostingModel="InProcess">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
  </environmentVariables>
</aspNetCore>