简体   繁体   English

使用Angular2的Azure IIS路由 - > 404

[英]Azure IIS routing with Angular2 --> 404

We have a website on Azure using a REST back-end written in C# and a front-end written in Angular2. 我们在Azure上有一个网站,它使用一个用C#编写的REST后端和一个用Angular2编写的前端。

When I click on menus or buttons in the webpages the correct page is opened and the url is changed from <mydomain>/ to for example <mydomain>/client/16 This works fine and if I understand it correctly the Angular2 routing is taking care of this. 当我点击网页上的菜单或按钮时,会打开正确的页面并将网址从<mydomain>/更改为例如<mydomain>/client/16这很好用,如果我理解正确的话,Angular2路由正在照顾这个的。

But when I'm at this page <mydomain>/client/16 and hit F5 to refresh the browser I get a 404 error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. 但当我在这个页面<mydomain>/client/16并点击F5刷新浏览器时,我收到404错误: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Again if I understand it correctly this is handled by the IIS routing. 如果我理解正确,这将由IIS路由处理。

I've been reading posts about this for days and tried several suggestions, mostly adding rewrite rules to the Web.config but so far nothing worked. 我已经阅读了几天的帖子,并尝试了几个建议,主要是向Web.config添加重写规则,但到目前为止没有任何效果。

Locally we don't have this issue because we run the back-end within Visual Studio and the front-end in NPM. 在本地我们没有这个问题,因为我们在Visual Studio中运行后端,在NPM中运行前端。 This makes it very hard to debug and solve. 这使得调试和解决变得非常困难。

What should I do to solve this? 我该怎么做才能解决这个问题?

On the IIS forum I was pointed to How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode? 在IIS论坛上,我被指出如何在HTML5模式下为URL重写AngularJS应用程序配置IIS?

Adding this rule to my Web.config solved my issue: 将此规则添加到我的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>

I thought I had tried this one before, but apparently not completely ;) 我以为我之前尝过这个,但显然不完全;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM