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

Visual Studio发布Blazor WASM到第三方主机时web.config转换失效怎么办

问题排查与解决方案

1. 转换文件结构错误

你当前的Web.Staging.config多套了一层<location>节点,Blazor WebAssembly应用自动生成的web.config中,system.webServer节点直接归属于根<configuration>节点,不存在外层<location>节点,路径不匹配导致转换规则完全无法命中。
修改后的转换文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer xdt:Transform="InsertIfMissing">
        <httpProtocol xdt:Transform="InsertIfMissing">
            <customHeaders xdt:Transform="InsertIfMissing">
                <add name="blazor-environment" value="Staging"
                     xdt:Locator="Match(name)"
                     xdt:Transform="InsertIfMissing" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

2. 检查发布配置文件属性

在Staging.pubxml的<PropertyGroup>节点中添加以下配置,显式开启web.config转换功能:

<IsTransformWebConfigDisabled>false</IsTransformWebConfigDisabled>

3. 检查转换文件的项目属性

在Visual Studio中右键Web.Staging.config,选择「属性」,确认两项配置:

  • 生成操作:设置为None
  • 复制到输出目录:设置为不复制

4. 快速验证方法

修改配置后可以先选择发布到本地文件夹,直接查看输出的web.config是否已经插入预期配置,不需要每次发布到FTP验证,排查效率更高。

内容的提问来源于stack exchange,提问作者benjamin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 13:24:02