首页 > 解决方案 > 在 Azure 中托管时,Angular 应用程序刷新不起作用

问题描述

应用程序在本地工作,但是当我在 Azure 上托管它时,每当我按刷新时它会显示“您要查找的资源已被删除、名称已更改或暂时不可用。”

我找到了解决方案,例如将 web.config 文件放在根文件中,并将其添加到 angular-cli.json 文件的资产中,但随后应用程序根本无法运行,并且显示 500 内部服务器错误。

如果有人可以帮助我,我将不胜感激,因为我已经为此苦苦挣扎了很长时间。

标签: angularazurerefreshhosting

解决方案


您应该将 web.config 移动到“ src”文件夹而不是根目录。

web.config 也应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Angular4" 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>

摘自这篇文章:angular 2 azure deploy refresh error : The resource you are looking for has been removed, have its name changed, or is临时不可用


推荐阅读