HTTP 错误 500.19 - 内部服务器错误 (0x8007000d)

问题描述

我正在尝试将 .Net Core 5 WASM 应用部署到全新的 Windows Server 2019 虚拟服务器,并且遇到非常通用的 The requested page cannot be accessed because the related configuration data for the page is invalid. 错误消息。

通过添加/删除程序,我已确认我已安装 .Net Core 5.02 Windows Server Hosting、Runtime(x64 和 x86)和 5.0.102 x64 SDK。我读过这可能是一个权限问题,所以我授予了每个人对站点所在的所有文件的完全控制权(显然是临时的!)并在 IIS 中确认安装了 .Net Core 模块。

当我尝试通过 IIS 编辑配置文件时,我得到了这个提示,所以我知道它对 web.config 的某些东西很生气,但我一生都无法弄清楚是什么。

enter image description here

完整的 web.config 文件(通过 VS [应用程序工作正常] 发布到本地文件夹,然后将其复制到 Web 服务器生成)对我来说看起来非常基本。有任何想法吗?我在这里搜索的所有内容都说明了权限或有关错误配置的 web.config 的内容,但没有什么明显的突出。这是完整的配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
  <customErrors mode="Off" />
  </system.web>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".blat" />
      <remove fileExtension=".dat" />
      <remove fileExtension=".dll" />
      <remove fileExtension=".json" />
      <remove fileExtension=".wasm" />
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
    </staticContent>
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/octet-stream" enabled="true" />
        <add mimeType="application/wasm" enabled="true" />
      </dynamicTypes>
    </httpCompression>
    <rewrite>
      <rules>
        <rule name="Serve subdir">
          <match url=".*" />
          <action type="Rewrite" url="wwwroot\{R:0}" />
        </rule>
        <rule name="SPA fallback routing" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="wwwroot\" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

解决方法

经过反复试验,我终于弄明白了! <rewrite /> 部分是最令人抓狂的地方,我必须安装 Microsoft 的 URL Rewrite Module 才能使其正常工作。如果提供的错误消息不是“我无法阅读此内容”,而是说“未知部分 <rewrite />,但至少现在可以使用。

希望这个小花絮能帮助其他人建立一个新的网络服务器!

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...