Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Web App does not load .json file

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!

like image 773
LTanase Avatar asked Jan 07 '18 13:01

LTanase


1 Answers

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

<staticContent>
  <remove fileExtension=".json"/>
  <mimeMap fileExtension=".json" mimeType="application/json"/>
</staticContent>

under the nodes

<configuration>
   <system.webServer>

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 :)

like image 103
Lorenzo Montanari Avatar answered Sep 24 '22 03:09

Lorenzo Montanari