0
votes

I hosted my angular2 application in IIS and when I browse the application it is loading properly, when I refresh the page it is showing 404 error. To solve this I followed these links

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
I created the following rule by referring the above two links

<?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>

If I refresh the page it should load the same page with all the changes being reverted, but it is not working as expected. Can anyone help me on this?

1
is it pure UI or you also have MVC in the code behind which has first routing routingRohit Ramname
@RRForUI: It is pure UI no MVC in the code. I created rule in IIS using URL Rewriter and it created the web.config file as I mentined in my question.thamatam kiran

1 Answers

0
votes

I changed my code in web.config file as follows and it is working fine.

<?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>