【问题标题】:Angular 4/2 application hosting on IISIIS 上的 Angular 4/2 应用程序托管
【发布时间】:2018-01-15 23:35:36
【问题描述】:

我正在尝试在 IIS 10 上托管我的 Angular 4 应用程序,并且在 通过单击应用程序内的任何链接重定向到另一个路由,但是当我在 URL 中键入相同的链接时,我收到 404 错误消息。

我浏览了 Angular 文档,它说我没有创建一个回退到 index.html,我使用 URL Re write 在 IIS 级别上做了,它没有工作。

我的托管应用程序 URL 是 http://localhost:86/

这是我在 IIS 中添加为网站的应用程序文件夹的结构:

基础href是<base href="/">

有什么问题吗?

还有一件事,是不是通过使用这个后备用户将无法键入 url,因为它会重定向到 index.html?

【问题讨论】:

  • 你可以试试 base href="./" 吗?
  • 尝试在webconfig默认页面中设置index.html
  • 它不起作用?
  • 尝试将 routerModule 配置为 useHash:true
  • 你能分享你在 IIS 上的 URL 重写配置吗

标签: angular web-hosting iis-10


【解决方案1】:

这是在托管应用的 webconfig 中需要做的事情。

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

只需将其替换为 Web 配置的内容并考虑操作标记 url。我的基本网址是“/”。

谢谢

【讨论】:

    猜你喜欢
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-24
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多