Azure Web App does not load .json file

我只是一个虾纸丫 提交于 2020-07-08 05:26:28

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/48137750/azure-web-app-does-not-load-json-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!