2017-08-08 53 views
0

我在IIS中託管我的angular2應用程序,當我瀏覽正在加載的應用程序時,當我刷新頁面時,它顯示404錯誤。爲了解決這個我跟着這些鏈接創建規則刷新IIS中angular2應用程序的頁面

1)https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

2)http://jasonwatmore.com/post/2017/02/24/angular-2-refresh-without-404-in-node-iis
我參照上述兩個環節

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="LogViwerRouting"> 
      <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> 

如果我刷新頁面創建了以下規則它應該加載相同的頁面,並且所有更改都被恢復,但不能按預期工作。誰可以幫我這個事?

+0

是純粹的UI,或者您還可以在MVC後面已經第一路由的路由 – RRForUI

+0

@RRForUI代碼:它是純粹的UI代碼中沒有MVC。我使用URL重寫器在IIS中創建了規則,並在我的問題中引用了我創建的web.config文件。 –

回答

0

我改變了我的web.config文件中的代碼,如下所示,它工作正常。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="LogViwerRouting"> 
       <match url=".*" /> 
       <conditions logicalGrouping="MatchAll"> 
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" /> 
       </conditions> 
       <action type="Rewrite" url="./" appendQueryString="true" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer>