【问题标题】:Setup IIS Routing to allow Angular Routing to work设置 IIS 路由以允许 Angular 路由工作
【发布时间】:2019-08-01 23:55:23
【问题描述】:

我在 IIS 服务器 中部署了一个 angular 应用程序(前端应用程序)并部署了一个 asp.net Web API 应用程序(后端应用程序)端应用程序)在另一台服务器(使用不同的服务器角度应用程序和asp.net web API应用程序)。

当我转到 angular 应用程序 URL 时,我可以访问我的网页。当我单击菜单项时,角度路由器将我路由到请求的 URL,但是当我在浏览器中输入 请求的 URL 时,我收到 IIS 404 not found 错误。

我不知道是什么问题。

【问题讨论】:

标签: angular iis asp.net-web-api angular-ui-router


【解决方案1】:

发生这种情况是因为 IIS 对客户端路由一无所知,因此,您必须编写一个重写规则,说明始终将流量定向到未知 URL 到 Angular 应用程序的索引文件。完成此操作后,Angular 将负责提供正确的路由。

【讨论】:

    【解决方案2】:

    IIS 正在尝试路由您的请求。将 IIS 设置为重定向到 root。在 IIS 重定向到 root 之后,Angular Routing 将拾取路由的其余部分。

    这是我的 Web.config 中的内容。

    <rule name="Force Index.html" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{REQUEST_URI}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2016-10-16
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 2015-08-13
      • 2019-07-04
      相关资源
      最近更新 更多