c# - 使用 Angular2 进行 Azure IIS 路由 --> 404

标签 c# rest azure iis asp.net-web-api-routing

我们在 Azure 上有一个网站,使用用 C# 编写的 REST 后端和用 Angular2 编写的前端。

当我单击网页中的菜单或按钮时,会打开正确的页面,并且 URL 将从 <mydomain>/ 更改为例如<mydomain>/client/16 这工作得很好,如果我理解正确的话,Angular2 路由就会处理这个问题。

但是当我在这个页面 <mydomain>/client/16并按 F5 刷新浏览器,我收到 404 错误:The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 如果我理解正确的话,这是由 IIS 路由处理的。

我几天来一直在阅读有关此问题的帖子,并尝试了一些建议,主要是向 Web.config 添加重写规则,但到目前为止没有任何效果。

在本地,我们没有这个问题,因为我们在 Visual Studio 中运行后端,在 NPM 中运行前端。这使得调试和解决非常困难。

我应该怎么做才能解决这个问题?

最佳答案

在 IIS 论坛上,我被指向 How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?

将此规则添加到我的 Web.config 解决了我的问题:

    <rule name="AngularJS Routes" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>

我以为我以前尝试过这个,但显然没有完全尝试过;)

关于c# - 使用 Angular2 进行 Azure IIS 路由 --> 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40038776/

相关文章:

php - 如何在PHP中使用curl获取数据?

azure - Azure 可用性集和规模集的差异

c# - 通过在 Windows Phone 的 Sqlite 数据库中运行 sql 查询来创建匿名类型列表

c# - 比较 SQL C# 中的日期

python - 如何使 Django REST Framework 返回超链接列表而不是一个列表中的所有数据?

java - 从同一后端支持移动应用程序和网站的最佳技术堆栈是什么?

azure - Akka.NET 记录器不将日志发送到 Application Insights

azure - 如何将项目代码从本地计算机导入到Azure Repos?

Datagridview 单元格的 C# Switch-case 循环

c# - .NET从本地报告读取ReportParameter