404 - 未找到文件或目录。进入Windows服务器

问题描述 投票:0回答:1

我使用 React 作为前端,使用 .NET Core 作为后端。在本地环境中一切正常,但当我将其部署到实时服务器时,出现 404 - 文件或目录未找到错误。我一直无法找到解决方案。请帮助我。enter image description here

reactjs .net-core iis server
1个回答
0
投票

React 使用客户端路由,但 IIS(或任何服务器)处理服务器端路由。确保您将服务器配置为为所有路由提供index.html。如果您使用的是 IIS,您可以通过更新 web.config 文件来完成此操作:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
© www.soinside.com 2019 - 2024. All rights reserved.