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

后端 未结 4 1005
醉酒成梦
醉酒成梦 2020-11-30 22:36

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

相关标签:
4条回答
  • 2020-11-30 22:50
    • 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']

    0 讨论(0)
  • 2020-11-30 22:59

    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>
    
    0 讨论(0)
  • 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>
    
    0 讨论(0)
  • 2020-11-30 23:12

    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>
    
    0 讨论(0)
提交回复
热议问题