You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Blazor WASM部署IIS后刷新非首页报404错误的解决方法

Blazor WASM部署IIS后刷新子页面404的解决方法

本地IIS部署Blazor WASM示例应用后,通过托管端口可正常访问所有页面,但刷新Counter或Weather页面时出现HTTP Error 404.0 - Not Found错误,首页刷新正常,其他两个页面存在该问题,从浏览器网络标签页可见,刷新时浏览器会直接请求weather等子页面对应的物理文档。尝试过公开方案无效,以下是正确解决步骤:

  • 安装IIS的URL Rewrite模块
  • 若项目输出目录中没有web.config文件,新建该文件并添加以下重写规则代码:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- Clear all rules -->
        <clear />
        <!-- Rewrite all requests not pointing to a file or directory to index.html -->
        <rule name="Serve index page" 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="/index.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

该规则会捕获所有指向非文件、非目录的请求,将其重写到index.html,确保Blazor应用接管后续的导航逻辑。

内容的提问来源于stack exchange,提问作者Dixan Lal Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 03:42:49