My first Azure website is a simple test site I've had for a while that makes ajax calls back to the server for JSON data. All the data files have .json extensions. Azure will not 'see' these files. If I change the extension to .txt it servers them up fine.
Do I have to muck with IIS to get this .json to be seen?
I too found Ahmed Sabbour's blog post helpful, but it created an additional problem for me. Whilst the fix worked for the Azure Web App when I then tried to run the app locally it died horribly, throwing HTTP 500.19 everywhere. It took me a while to figure out how to fix this whilst maintaining a single web.config. The solution was (albeit a bit of a fudge) to remove the fileExtension first and then add it back in:
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
For my narrow purposes this was fine and I hope this might save someone time trying to figure this out.
Citing Ahmed Sabbour with his blog post http://blogs.msdn.com/b/africaapps/archive/2013/06/07/how-to-serve-static-json-files-from-a-windows-azure-website.aspx you have to do the following:
"If you upload a .json file to your Windows Azure website and try to access it, it would give you a 404 File Not Found error, because the MIME Type of .json is not set by default. This also applies in general to any file that might need a specific MIME Type.
To fix this issue, FTP into your website and upload the following Web.config file which will set the correct MIME types. If you already have a Web.config file in place, just add the below to the appropriate section.
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
". I did this and the 404 was gone.
It appears that Azure (Cloud Services, at least) knows how to serve JSON from a deployed ASP.NET MVC project. The problem in my case was that the Build Action on the JSON file's property page was not set correctly. Changing the Build Action to Content fixed it for me.
have you tried adding the specific MIME type to your server's config file?
http://www.iis.net/configreference/system.webserver/staticcontent/mimemap
If you add the mime type as
application/json; charset=utf
that should work.
Related
I published a json file on to my website using ftp. When I tried to access my site using mtsite.com/abc.json it throws the below error.
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
My file is on hosted site on azure. Even if file in on server why did it say that file is not found?
Any place in azure portal where I can add or allow Mime type json? I cannot add web.config file as My files are all HTML and Json.
By default IIS (and so the Azure App Service) doesn't serve .json files. You need to enable this feature in your web.config. If don't already have one, create it in the root directory.
Open your web.config and place this code
<staticContent>
<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json"/>
</staticContent>
under the nodes
<configuration>
<system.webServer>
And it should be fixed.
Here you can find a basic web.config template that i've made a while ago
P.S: Even though you are using only HTML and JSON, this is the only way to go (as there is not a UI solution in the portal). In this way you could also control other aspect of your website, for example the redirect to HTTPS for the HTTP requests.
I have the following HTML in my Azure Web Application:
Please complete and return the
Terms of Service
The .csproj file does have this pdf included in it:
When I click "Launch Google Chrome" to test locally in Visual Studio and when I click on "Terms of Service", I get the following error:
But the file is there! It is on my file system. There is no encoding necessary. Why is this error shown and why can't the PDF be downloaded from the web app? Do I need another step to publish it? Please help!
By default, contents of Views folders are not supposed to be accessed by the normal request pipeline. The Views folder is home for the view files (.cshtml) which will be executed by the view engine. If you look at the web.config file located inside ~/Views you can see that we have a BlockViewHandler registered which prevents direct file access to all files.
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler" />
</handlers>
You should consider moving your pdf file to a Statics directory in the app root and point to that.
Now, point to that location
Terms of Service
You can give your own name for the directory. Some people like to keep it under the Content directory. So it is more of a personal preference.
In asp.net core, the wwwroot directory is the static content home by default. So you may keep your static contents inside that (this is overridable)
You could make changes to the web.config located in the views directory to allow direct browsing, but the more solid approach is to not pollute the convention and move the static assets to it's own folder. If you absolutely want to enable direct file access to the view directory, you can update the path attribute value to tell mvc to prevent access to only files with a specific extension. Here is how you will prevent only .cshtml files ( so pdf will work)
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode"
type="System.Web.HttpNotFoundHandler" />
</handlers>
I am trying to read a json file from my visual studio 2013 environment. It is throwing some error as mentioned below
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
However its working fine on plnkr http://plnkr.co/edit/std1ngB40YIJBmC94Zdm?p=preview
Can someone please let me know how to resolve the same ?
Error screen shot
Folder Structure
Have you set up the mime map correctly? I only see a screenshot for the handler mapping.
Open IIS Manager
Display properties for the IIS Server
Click MIME Types and then add the JSON extension:
File name extension: .json MIME
type: application/json
Go back to the properties for IIS Server
Click on Handler Mappings
Add a script map
Request path: *.json
Executable: C:\WINDOWS\system32\inetsrv\asp.dll
Name: JSON
If this still fails to work remove the script map completed and just stick with the mime map, I do not know why you are adding the script map in the first place.
I done lot of research on this issue and finally its resolved :) :)
I tried the answer given by #James Trotter as well but didn't get success.
I don't know why MIME in IIS didn't work but it worked when I added it in web.config
SOLUTION :
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
For More Information
Allow loading of JSON files in Visual Studio Express 2013 for Web
I cannot download certain file types from website. In particular .frm, .frx, .mgf. Getting error: HTTP Error 404 - File or directory not found. I added these file types in IIS as local, it did not help. Can I add any kind of code to the webpage to allow downloading of such files?
All need to be done on the website hosting server, not on downloading computer. Daaahhh. Make sure your hosting account was switched to IIS7.
web.config file need to be created (can be done in Notepad) and placed in the root directory of the website.
web.config file for allowing download of .mgf files:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mgf" mimeType="text/plain" />
</staticContent>
</system.webServer>
</configuration>
I have a web application that I'm trying to install in my local IIS. I'm using IIS 7.5. The problem I'm having is that my application comes up but my css styles gives me Resource interpreted as Stylesheet but transferred with MIME type text/html error. This only happens while I'm not authenticated in the application. So I tried different options for this error.
Verified my MIME type on the application. The .css type is set to type/CSS.
Verified all my permissions for the folder in the Security Tab. Assigned to IIS_IUSRS and for NETWORK SERVICE groups Full Control to the Root folder. (Even tried adding Everyone to share with Read/Write access)
The only thing that "worked" was adding the specific CSS folder to my web.config. The problem with this approach is that I didn't needed to do this before for this application. So there should be something that is causing this problem.
<location path="css">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
Also tried adding the .htaccess file (even though this is not Apache). To see if this worked and not.
Verified the Static Content that is checked in the Add Features section.
I'm running out of options for this one. If anyone know anything else that should be consider, will be very appreciated.
Thanks in advance.
I had a similar problem once and I was able to solve it by re-installing the IIS
Hope that helps!