2017-08-08 52 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>