英文:
Serve JSON static files from Azure WebApp
问题
When I try to access JSON files served through the Azure web app, I get a 404 error (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable). Almost every resource I managed to find on the internet suggests adding MIME type for .json
extension to the <system.webServer>
section of the web.config
file, like so:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
or somewhere:
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
But it does not work for me.
Indeed, when I go to the Kudu console and log the staticContent
section with the following command:
%windir%\System32\inetsrv\appcmd list config /section:staticContent
it shows what I assume is the correct MIME type for JSON files (<mimeMap fileExtension=".json" mimeType="application/json" />
).
However, trying to access https://appname.azurewebsites.net/some-folder/example.json returns a 404 error. I tried placing other files inside the same directory (txt, css, js, png, font files, etc), and they are all served without any trouble, except for the JSON.
I really don't know how to approach this any further, and I would appreciate some help here.
英文:
When I try to access JSON files served through the Azure web app I get 404 (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.). Almost every resource I managed to find on the internet suggests adding MIME type for .json
extension to the <system.webServer>
section of the web.config
file, like so:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
or somewhere:
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
But it does not work for me.
Indeed, when I go to the Kudu console and log staticContent
section with the following command:
%windir%\System32\inetsrv\appcmd list config /section:staticContent
it shows what I assume is the correct MIME type for JSON files (<mimeMap fileExtension=".json" mimeType="application/json" />
).
However, trying to access https://appname.azurewebsites.net/some-folder/example.json returns 404. I tried placing other files inside the same directory (txt, css, js, png, font files, etc) and they are all served without any trouble, except for the JSON.
I really don't know how to approach this any further and I would appreciate some help here.
答案1
得分: 1
你需要确保要访问的JSON文件存在于服务器上的正确目录中。尝试清除浏览器缓存并重新加载页面,以查看JSON文件是否正确提供。
另外,你可以启用失败请求跟踪来捕获IIS中的详细错误,它将提供关键的错误和警告,帮助你识别问题。
这是一个参考文档:使用IIS跟踪来排除故障
英文:
You need to make sure that the JSON file you are trying to access exists in the correct directory on the server. Try clearing your browser cache and reloading the page to see if the JSON file is served correctly.
Also, you can enable Failed Request Tracing to capture detailed errors in IIS, it will provide key errors and warnings which will help you identify the problem.
This is a reference document: Troubleshooting Failed Requests Using Tracing in IIS
答案2
得分: 0
我可以为您提供以下翻译部分:
- 在
Azure App Service
上部署时,可以同时从本地和已部署的Azure App Service
上提供JSON
文件。
请查看以下步骤。
在VSStudio
中,在wwwroot
目录中创建一个新文件夹,并添加.json
文件。
- 将应用程序部署到
Azure App Service
。 - 确保您的文件夹在KUDU控制台的
site\wwwroot\wwwroot
文件夹中正确部署。
示例 .json 输出:
英文:
I am able to serve the JSON
files both locally and from the deployed Azure App Service
.
Check the below steps.
In VSStudio
, Create a new folder in the wwwroot
directory and add the .json
files.
- Deploy the Application to
Azure App Service
. - Make sure your folder is deployed correctly in the
site\wwwroot\wwwroot
folder in KUDU Console.
Sample .json Output:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论