0
votes

I am trying deploying my application to IIS server on windows 7 PC. The web address is

http://localhost/myapp

  1. I installed URL rewrite.
  2. Here is my web.config content

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <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="/MyApp/" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

My application runs very good using "ng serve" on my computer. When I deployed on IIS on windows 7 PC, the application cannot access resources like images, json files. I got 404 error. I think there is something wrong in my web.config file. The file, en.json, is located c:\inetpub\wwwroot\myapp\assets\i18n folder after it is deployed. Please help.

2
In IIS do you have default website mapped to c:\inetpub\wwwroot\myapp directory? Please share the details of how you have setup the Angular6 app in IISMohsin Mehmood
Sounds like you need to set your base href tag to /myapp angular.io/guide/deployment#base-taguser184994
The application is mapped to c:\inetpub\wwwroot\myapp. The base_href is "/myapp/".user3097695

2 Answers

1
votes

The problem was that IIS 7 doesn't have ".json" as default file extension. Here is web.config to add the ".json".

<configuration>
<system.webServer>
        <security>
            <requestFiltering>
                <fileExtensions>
                    <add fileExtension=".json" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <staticContent>
            <remove fileExtension=".json" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
</system.webServer>
</configuration>

The ".json" file extension is a default one in ISS 8. I have to remove it before adding it.

0
votes

altere o Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

 

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <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="./index.html" />
      </rule>
    </rules>
  </rewrite>
   <security>
            <requestFiltering>
                <fileExtensions>
                    <add fileExtension=".json" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <staticContent>
            <remove fileExtension=".json" />
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>
</system.webServer>

 

</configuration>