Allow loading of JSON files in Visual Studio Express 2013 for Web

55

I have the problem, that the IIS from Visual Studio Express 2013 for Web doesn't allow the loading of *.json files. When trying to load a *.json file I get a 403 Forbidden and a help page how to configure the IIS allow the loading of JSON files, but don't know what to do with this information / where the IIS is even located.

This is the error page:

HTTP Error 404.3 - Not Found 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.

Most likely causes: It is possible that a handler mapping is missing. By default, the static file handler processes all content. The feature you are trying to use may not be installed. The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.) If ASP.NET is not installed.

Things you can try: In system.webServer/handlers: Ensure that the expected handler for the current page is mapped. Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool. Pay extra attention to typographical errors in the expected handler line. Please verify that the feature you are trying to use is installed. Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe. To set a MIME type, run the following command in the IIS Express install directory: appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string'] The variable fileExtension string is the file name extension and the variable mimeType string is the file type description. For example, to add a MIME map for a file which has the extension ".xyz": appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain'] Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them. Install ASP.NET. Check the failed request tracing logs for additional information about this error. For more information, click here.

Detailed Error Information: Module StaticFileModule Notification
ExecuteRequestHandler Handler StaticFile Error Code 0x80070032 Requested URL http: //localhost:64107/Settings/Settings.json Physical Path D:\GIT\RepoP_Paneon\Settings\Settings.json Logon Method Anonymous Logon User Anonymous Request Tracing Directory
C:\Users\stefank\Documents\IISExpress\TraceLogFiles\REPOP_PANEON

More Information: This error occurs when the file extension of the requested URL is for a MIME type that is not configured on the server. You can add a MIME type for the file extension for files that are not dynamic scripting pages, database, or configuration files. Process those file types using a handler. You should not allows direct downloads of dynamic scripting pages, database or configuration files. View more information ยป

iis
visual-studio-2013
asked on Stack Overflow Oct 22, 2013 by Stefan

4 Answers

168

After some more googling, and experimenting I found out, that you have to define IIS settings in the Web.config.

After adding the following configuration:

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

it works like a charm.

Full setup file example:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>
</configuration>
answered on Stack Overflow Oct 22, 2013 by Stefan • edited May 3, 2015 by Iman Mahmoudinasab
14

Better add remove tag in case future IIS has build in json support. This is my web.config section of mimeMap.

<system.webServer>
  <staticContent>
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
<system.webServer>
answered on Stack Overflow Aug 6, 2015 by (unknown user)
6

We may need to distinguish the Visual Studio development environment (with IIS Express) from local IIS and a remote server (like Azure WebSites). To specifically target IIS Express, for example, we edit %USERPROFILE%\Documents\IISExpress\config\applicationhost.config under system.webServer/staticContent:

<mimeMap fileExtension=".json" mimeType="application/javascript" />

I need to make this distinction because my local (intranet) IIS already has the JSON mime type defined. So when I deploy to Azure websites I use this transformation in Web.Release.config:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".json" mimeType="application/javascript" xdt:Transform="Insert" />
    </staticContent>
</system.webServer>
answered on Stack Overflow Jun 9, 2015 by rasx
5
  • Open CMD with administrator privilages.
  • Go to:

    cd C:\Program Files\IIS Express or
    cd C:\Program Files (x86)\IIS Express

  • Run command:

    appcmd set config /section:staticContent /+[fileExtension='JSON',mimeType='application/x-javascript']

answered on Stack Overflow Mar 13, 2015 by mattinsalto • edited May 3, 2015 by Iman Mahmoudinasab

User contributions licensed under CC BY-SA 3.0