【问题标题】:Location Strategy while hosting on IIS server在 IIS 服务器上托管时的位置策略
【发布时间】:2020-04-06 12:49:45
【问题描述】:

我在本地服务器上运行我的应用程序,它工作正常,当我们托管它时,它开始工作正常,直到我刷新页面并发生 404 错误。

然后我想出了使用 HashLocationStrategy 的解决方案。它工作得很好。但它在我的网址中添加了一个“#”符号作为“http://everest.syslogix.ca/#/fastcom/admin-dash”。但它工作得很好。之后,我想在此应用程序中添加linkedIn登录,但它需要一个不带“#”符号的受信任网址。

现在我该怎么办?我在互联网上搜索过,尝试了很多解决方案,但没有一个对我有用。我想要一个没有哈希的 URL,它在我重新加载页面时可以正常工作。或者我想要某种方法来启用带有哈希的 URL 作为受信任的 URL 存储在 linkedIn 上。

【问题讨论】:

标签: angular iis linkedin-api hash-location-strategy


【解决方案1】:

解决了!!

1- 创建一个 web.config 文件,其文本为:-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>

  </system.web>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular 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="/index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

2- 将此文件放在 src 文件夹中。 3- 修改您的 angular.json 文件以包含 web.config 文件,在资产标签中为:

"

assets": [
              "src/favicon.png",
              "src/assets",
              "src/web.config"
                        ],

4-ng 构建 --prod 5-发布和享受。

【讨论】:

    【解决方案2】:

    您必须将重写规则添加到 web.config 文件并将其放在生产构建文件夹中,您还可以在同一 here 上找到文档。

     <system.webServer>
      <rewrite>
        <rules>
          <rule name="Angular 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="/index.html" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
    

    【讨论】:

    • 我只是应该添加网络配置文件?在哪里添加它?在根文件夹中?生产前还是生产后?
    • 是的,您必须在生产之前将它放在根文件夹中,并且在创建生产构建时它也应该自动添加到生产构建文件夹中。
    • 在应用程序的 src 文件夹中添加了 web.config 文件。然后使用 ng build --prod。命令来创建应用程序的生产版本。 URL 重写已安装在 IIS 上。再次无法正常工作。该应用程序托管在 everest.syslogix.ca ,是否需要在重写 url 中提供这个?
    猜你喜欢
    • 2021-03-27
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多