How to allow download of .json file with ASP.NET

前端 未结 6 1119
清酒与你
清酒与你 2020-11-28 20:37

How can I enable the download of *.json files from an old ASP.NET site (IIS6 I am led to believe)?

I am getting a 404 page instead of the JSON file.

Do I nee

相关标签:
6条回答
  • 2020-11-28 21:17

    When adding support for mimetype (as suggested by @ProVega) then it is also best practice to remove the type before adding it - this is to prevent unexpected errors when deploying to servers where support for the type already exists, for example:

    <staticContent>
        <remove fileExtension=".json" />
        <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
    
    0 讨论(0)
  • 2020-11-28 21:19

    Solution is you need to add json file extension type in MIME Types

    Method 1

    Go to IIS, Select your application and Find MIME Types

    Click on Add from Right panel

    File Name Extension = .json

    MIME Type = application/json

    After adding .json file type in MIME Types, Restart IIS and try to access json file


    Method 2

    Go to web.config of that application and add this lines in it

     <system.webServer>
       <staticContent>
         <mimeMap fileExtension=".json" mimeType="application/json" />
       </staticContent>
     </system.webServer>
    
    0 讨论(0)
  • 2020-11-28 21:35

    If you want to manually add support to your site, you can just add the following to your web.config in the system.webServer section:

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

    This will add a "local" configuration under IIS. This does not work in IIS6, but does work in IIS7 and newer.

    0 讨论(0)
  • 2020-11-28 21:36

    Add the JSON MIME type to IIS 6. Follow the directions at MSDN's Configure MIME Types (IIS 6.0).

    • Extension: .json
    • MIME type: application/json

    Don't forget to restart IIS after the change.

    UPDATE: There are easy ways to do this on IIS7 and newer. The op specifically asked for IIS6 help so I'm leaving this answer as-is. But this answer is still getting a lot of traffic even though IIS6 is very old now. Hopefully you're using something newer, so I wanted to mention that if you have a newer IIS7 or newer version see @ProVega's answer below for a simpler solution for those newer versions.

    0 讨论(0)
  • 2020-11-28 21:36

    Just had this issue but had to find the config for IIS Express so I could add the mime types. For me, it was located at C:\Users\<username>\Documents\IISExpress\config\applicationhost.config and I was able to add in the correct "mime map" there.

    0 讨论(0)
  • 2020-11-28 21:41
    1. Navigate to C:\Users\username\Documents\IISExpress\config
    2. Open applicationhost.config with Visual Studio or your favorite text-editor.
    3. Search for the word mimeMap, you should find lots of 'em.
    4. Add the following line to the top of the list: .
    0 讨论(0)
提交回复
热议问题