14

I have a problem with an Azure Web App, as it does not load a .json file that is located on the server. The app is running fine until it needs to load the data from the .json file. The event is triggered by clicking a button that runs a javascript code that makes a XmlHttpRequest call.

This is the jQuery code (placed inside mvc_test.js file) that makes the request:

$(document).ready(function () {

    var model = {
        userLanguage: 'en-EN',

        getData: function() {
            return $.ajax({
                    url: "https://easyfabric.azurewebsites.net/js/clauses_array.json",
                    type: "GET",
                    dataType : "json", //"text"
                    timeout: 5000
                });
        }
    };

I have used an absolute path to the resource, but i received the same error using a relative path.

The code above should get the data and pass it to a function that will print the data to the console.

It had worked before, but then i have changed intentionally to a wrong path for testing a modal window containing an error message. When i changed back to the correct path (yesterday) i start receiving 404 Errors. I have moved the ***.json file***in the same folder with the javascript file that makes the xhr request but does not work either. The index.html, .css and .js files, jquery and office-ui frameworks are loaded without problems.

The content of the app is deployed to the server from a github repository.

The Failed Request Tracing log in the Diagnostic section of Azure Portal gives me a warning of SECURITY_DENIED_BY_MIMEMAP and a MODULE_SET_RESPONSE_ERROR_STATUS.

Seems that some security setting on the server denies the access to the .json file. But it is strange that the .js file from the same folder is loaded ( as I have cleared the cache of my browser) and .json file is not.

Can anyone shed some light to this problems and how can be solved?

Thanks!

Rob
  • 14,746
  • 28
  • 47
  • 65
LTanase
  • 197
  • 2
  • 15

1 Answers1

34

I had the same problem a few months ago. I've fixed it by adding to the web.config these lines of code

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".json"/>
      <mimeMap fileExtension=".json" mimeType="application/json"/>
    </staticContent>
  </system.webServer>
</configuration>

This essentially says to IIS to serve ALL .json files as a static file, as by default this feature is disabled.

If you don't have a web.config file you need to create it in the root folder of your website.

I hope I helped you :)

Greg K
  • 10,770
  • 10
  • 45
  • 62
Lorenzo Montanari
  • 958
  • 1
  • 15
  • 19
  • Thanks Lorenzo for your answer! I do not have an web.config file in the _wwwroot_ folder of the site. Is there anything needed to add to the web.config file besides those mentioned in your answer? There are some resources/references how a basic web. config should look like for an Azure App? – LTanase Jan 07 '18 at 14:19
  • 1
    I've created a basic `web.config` template. You can find it [here](https://gist.github.com/l0ll098/9388c6c3808e1019beddd4bb8012f3c4) . As for the resources [this](https://www.tutorialspoint.com/asp.net/asp.net_configuration.htm) is a pretty good tutorial and cover many things. For more specific stuff, you can find it on the Internet. P.s.: Keep in mind that the `web.config` file depends on what are your needings and which language you are using (e.g.: the .Net Core `web.config` is slightly different from the one used for a NodeJs project) – Lorenzo Montanari Jan 07 '18 at 14:37
  • The problems was solved by your web.config file. Thank you for your help! – LTanase Jan 07 '18 at 15:23
  • You saved me! Thanks a ton! – Abhay Bh Jan 14 '21 at 08:23