【问题标题】:Creating rules to refresh the the page for angular2 application in IIS创建规则以在 IIS 中刷新 angular2 应用程序的页面
【发布时间】:2018-01-16 03:41:05
【问题描述】:

我在 IIS 中托管了我的 angular2 应用程序,当我浏览应用程序时它正在正确加载,当我刷新页面时它显示 404 错误。为了解决这个问题,我点击了这些链接

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>

如果我刷新页面,它应该加载相同的页面,所有更改都将被还原,但它没有按预期工作。谁能帮我解决这个问题?

【问题讨论】:

  • 是纯 UI 还是你的代码中也有 MVC,其背后有第一个路由路由
  • @RRForUI:纯UI,代码中没有MVC。我使用 URL Rewriter 在 IIS 中创建了规则,它创建了我在问题中提到的 web.config 文件。

标签: angular iis url-rewriting


【解决方案1】:

我在 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> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多