0

I have a project in Anglular 4 which has services getting JSON data from 'assets' folder. I created the dist folder with 'ng build' command and then added to IIS under default sites. In the 'index.html', I set .

The Index page loads ok using url like -

http://bla1.bla2.bla3.com/DistFolder

However, I get error for the files i am referring in my service withing the 'assets' folder. I have some jsons and png file in that assets folder.

I get error like below -

Get http://bla1.bla2.bla3.com/assets/somefile.json 404 (not found)

Your help is much appreciated.

Thanks in advance.

far007ial
  • 33
  • 4

1 Answers1

1

Assuming you use IIS 7.5 as the tag says and not a later version, make sure you enable the JSON mime type to be served in IIS. Basically add a web.config to the root folder (where your index.html is) with this in it:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" /> 
        </staticContent>
    </system.webServer>
</configuration>
Andrei Matracaru
  • 3,511
  • 1
  • 25
  • 29
  • Hi Andrei, This issue doesn't look to be with JSON as I got same error for a png file I have in the assets folder. I have mentioned that too in my question. – far007ial Aug 25 '17 at 17:03
  • Thanks Andrei your answer was helpful. However, I had to resolve the issues as below to make it work. i. I was referring to the asset folder as /asset/some.json rather than ./assets/some.json in my code. ii. I had to enable json as you suggested iii.I had to add in web.config file with a URL Rewrite rule as per link below: https://blogs.msdn.microsoft.com/premier_developer/2017/06/14/tips-for-running-an-angular-app-in-iis/ – far007ial Aug 26 '17 at 17:09
  • Glad it helped. FYI, for point 3, there is an even easier way to solve that problem without having to install the URL Rewrite module. Check my answer on [this post](https://stackoverflow.com/a/45844151/6139866) for the solution. – Andrei Matracaru Aug 26 '17 at 20:44