Loading json file gives code 404.3 - json

I have DataTables translations stored in .json file. In debug mode I get code 404.3.
I have read many articles about this problem but I can't find anything helpful.
I've added the section below to config file but this did not help.
This MIME type is also configured in my IIS.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>

You could try to simply rename the file to .txt, it should work just fine.

Related

Error 404 on Angular 2 app when deployed to Azure

I have an angular 2 app with a simple server.js as a node.js BE.
I have deployed my application to Azure and I'm at the point that the application loads and shows me the welcoming page.
When I reach a component that tries to read a local JSON via an HTTP request I'm getting a 404 error (that I don't receive in my local environment).
The code to read the json is the following:
private ReadFromJson(path: string): Observable<string[]> {
return this._http.get(path)
.map((response: Response) => <string[]>response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
where the actual path passed is the one showed in the console.
I have done two things: First I made sure that the file is actually there using the Azure CLI, and it is there as expected.
Secondly, after viewing many posts the only other solution I found was to add the MIME type as suggested here, but that didn't work for me as well.
I would really like some help in understanding and be troubleshooting the problem, any suggestion is welcomed!
Update:
If your app is just front-end (Angular) app, then you no longer need to serve these static files via Node.js. Because by default Azure App Service have installed IIS on it and IIS can serve any file type by doing some configuration. So, in this case, you can just keep web.config looking like below and put it to "site/wwwroot/dist".
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
As you deployed a Node.js on Azure App Service, which would host your app using iisnode, and you probably have a web.config file that looks like the content in this link.
By default, this configuration file assumes the static file in the /public folder.
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}" />
</rule>
So, after you add this to web.config,
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
please make sure the static files were put into /public file.
I ran into the same problem last week and thought maybe i should share my findings since i got it to work as desired.
I deployed the app developed using angular cli and built using the same. I copied over all files in the /dist folder over to azure and added a web.config (this was a lot of hit and trial) but i learned that a rewrite rule for angular was required which can process the webpack bundled assets and not return a 404.
Here is the web,config and i believe it should work for you as-is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="32768" />
</requestFiltering>
</security>
<rewrite>
<rules>
<rule name="AngularJS" stopProcessing="true">
<match url="^(?!.*(.bundle.js|.bundle.map|.bundle.js.gz|.bundle.css|.bundle.css.gz|.png|.jpg|.ico|.svg|.eot|.woff|\​.woff2)).*$" />
<conditions logicalGrouping="MatchAll"></conditions>
<action type="Rewrite" url="/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<staticContent>
<remove fileExtension=".svg" />
<remove fileExtension=".eot" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</configuration>
<!--
This is required for the app to work in Azure or an ASP.NET hosting environment because the woff files
are not treated as static content on Azure as well as the routing breaks without the rewrite rule below
and app or rather the server returns a 404.
-->
Below suggestion worked wonders.
If your app is just front-end (Angular) app, then you no longer need to serve these static files via Node.js. Because by default Azure App Service have installed IIS on it and IIS can serve any file type by doing some configuration. So, in this case, you can just keep web.config looking like below and put it to "site/wwwroot/dist".
Adding web.config worked
Thanks for excellent solution.

How to fix error regarding image not found if there is a mime type json?

I got this code in my web.config
<staticContent>
<remove fileExtension=".svg"/>
<remove fileExtension=".svgz"/>
<remove fileExtension=".eot"/>
<remove fileExtension=".otf"/>
<remove fileExtension=".woff"/>
<remove fileExtension=".jpeg"/>
<remove fileExtension=".jpg"/>
<remove fileExtension=".gif"/>
<remove fileExtension=".png"/>
<remove fileExtension=".bmp"/>
<mimeMap fileExtension=".jpeg" mimeType="image/jpeg"/>
<mimeMap fileExtension=".jpg" mimeType="image/jpeg"/>
<mimeMap fileExtension=".gif" mimeType="image/gif"/>
<mimeMap fileExtension=".png" mimeType="image/png"/>
<mimeMap fileExtension=".bmp" mimeType="image/bmp"/>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
<mimeMap fileExtension=".svgz" mimeType="image/svg+xml"/>
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/>
<mimeMap fileExtension=".otf" mimeType="font/otf"/>
<mimeMap fileExtension=".woff" mimeType="font/x-woff"/>
<mimeMap fileExtension=".json" mimeType="application/json"/>
</staticContent>
Now the problem is the image in my web got an error like this.
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
But whe i remove the <mimeMap fileExtension=".json" mimeType="application/json"/>
the image is rendered properly but the json file i have is not found.
How to fix this error regarding json mimetype and image. I want both of them found in my web.
Thank you
Look for more details than simply "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"
Does asp.net have a debug mode to make errors more verbose? If so enable it.
Check logs for more details.
A wild guess (limited by the level of detail given) is that you mess up the XML somehow and it fails.
Could you provide a link to the entire files w/ and w/o the mimeMap ?
(And be perfectly certain that one work and one fails..)
Then people can look for the error.
Another take:
Maybe you're lacking to define the .json file.
Try to add:
<remove fileExtension=".json"/>

ERROR 404.3 Not Found for JSON file

I have been getting the "ERROR 404.3 Not Found" for JSON file that I am calling using AJAX call on "Internet Information Services 7.5" even after I have activated all the "Application Development Features". Other than JSON file, all other files are getting loaded.
I am running an HTML page on IIS server on my local machine.
If I open the file directly then there is no problem at all. When I host the files on an online server it works fine.
Any quick help will be much appreciated.
As suggested by #ancajic i put the below code after connectionString tag in my web.config file and it worked.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
As said by #elasticman, it is necessary to open IIS Manager -> Mime types -> Add a new mime type with
Extension: .json
MIME Type: application/json
But for me that still wasn't enough. I have an ASP.NET MVC 4 application, and I had to modify my root Web.config file.
Insert
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
somewhere inside your
<system.webServer>
...
</system.webServer>
Is the file you try to receive in the same domain? Or do you fetch the json from another server? If it is hosted on a different domain, you'll have to use JSONP due to same origin policy.
Option 1
Go to IIs
Select Website
Double Click Mime Type Icon Under IIs
Click Add Link in right hand side
File Name Extension = .json
Mime Type = application/json
Click Ok.
Option 2
Update your web.config file like this
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
I hope your problem is resolved
If you are using IIS Express with Visual Studio, IIS Manager won't work for IIS Express. Instead, you need to open this config file from %userprofile%\documents\IISExpress\config\applicationhost.config and insert
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
along with all other pre-defined mime types.
I've applied the following settings on the IIS was right.
1.Open IIS Manager
2.Display properties for the IIS Server
3.Click MIME Types and then add the JSON extension:
File name extension: .json
MIME type: application/json
4.Go back to the properties for IIS Server
5.Click on Handler Mappings
Add a script map
Request path: *.json
Executable: C:\WINDOWS\system32\inetsrv\asp.dll
Name: JSON
I haven't the same problem but for me (Windows Server 2003 IIS 6) the MIME type application/json not work. I use text/plain and work perfect (You not need restart the server)
To solve this problem with an Azure App Service:
Use FTP or the Kudu dashboard to add this file one level above wwwroot--
/site/applicationHost.xdt:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" xdt:Transform="InsertBefore(/configuration/system.webServer/staticContent/*[1])" />
</staticContent>
</system.webServer>
</configuration>
Then, under Application settings in the Azure Portal, add a Handler mapping:
.json C:\WINDOWS\system32\inetsrv\asp.dll

Azure deployment with .json file extension

We are deploying an azure package where we have a static .json file. We have this working through the azure emulator and locally. but our application just spins when we run it in azure. We are getting a 404 on the app.json file. We have added the mime type to our local iis with the appropriate handler, below is what we have in our web.config. We have set the mime type of application/x-javascript but that didnt work either.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json"
mimeType="text/html" />
</staticContent>
<handlers>
<add name="JSON"
path="*.json"
verb="*"
modules="IsapiModule"
scriptProcessor="%path%\asp.dll"
resourceType="Unspecified"
preCondition="bitness64" />
</handlers>
</system.webServer>
Adding
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="text/html" />
</staticContent>
</system.webServer>
</configuration>
to my web.config in an Azure instance worked just fine. Most likely, your deployed web.config isn't configured properly. To check it out, enable RDP, connect to your Azure instance and browse to your web.config. Then you can fiddle with your web.config until you get things working.
Because you're serving up a static .json file, you don't need to add a .json HTTP handler. Also, the offical mime type for .json is application/json.

Allow MDB Downloads in IIS7

Currently if I am hosting an Access .MDB file to allow users to download, IIS7 is throwing a 404 error. I know the file is there and the permissions are fine. It appears to be a Handler issue, but I cannot figure out how to change the handler to allow downloading of MDB file. I assume I need to add something to the Handlers section of the web.config, but I am unsure of the syntax.
Thanks.
Or, if you don't want to modify a system-wide configuration file, you could add the following lines to that section in your web.config:
<remove fileExtension=".mdb" />
<add fileExtension=".mdb" allowed="true"/>
For example your Web.config should be similar to this:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true" >
<remove fileExtension=".mdb" />
<add fileExtension=".mdb" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Also see http://www.adamwlewis.com/articles/iis-7-not-serving-files-4047-error.
OK, found it.
Just need to remove the following line:
<add fileExtension=".mdb" allowed="false" />
in the "requestFiltering" section from the \Windows\System32\inetserv\config\applicationHost.config file.