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

Azure部署.NET 4.8+Vue2应用如何实现根URL访问无需加index.html

解决方案

该问题本质是托管.NET Framework 4.8应用的Azure App Service(Windows环境默认使用IIS托管)未将index.html设置为默认访问的首页文档,访问根路径时IIS无法匹配到默认资源就会返回404错误。

方法1:在Azure门户直接配置

  • 进入Azure门户,找到对应部署的Web应用服务资源页
  • 左侧菜单栏找到「设置」分类下的「默认文档」选项
  • 点击「添加」,输入index.html,将其拖动到默认文档列表的最顶部(保证优先级最高)
  • 点击「保存」,等待服务重启后即可生效

方法2:通过项目web.config文件配置(推荐,可随代码部署持久生效)

在.NET Framework项目根目录的web.config文件的<system.webServer>节点下添加如下配置:

<system.webServer>
  <!-- 配置默认首页文档 -->
  <defaultDocument enabled="true">
    <files>
      <add value="index.html" />
    </files>
  </defaultDocument>

  <!-- 若Vue项目使用history路由模式,需额外添加以下重写规则,避免页面刷新404;hash模式可省略该部分 -->
  <rewrite>
    <rules>
      <rule name="VueHistoryRouteFix" 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>

修改完成后重新发布项目到Azure App Service,配置会自动生效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 22:48:01