Cómo permitir la descarga de.archivo json con ASP.NET


¿Cómo puedo habilitar la descarga de *.archivos json de un antiguo ASP.NET sitio (IIS6 Me hacen creer)?

Estoy obteniendo una página 404 en lugar del archivo JSON.

Necesito crear una web.archivo de configuración? ¿Qué hay dentro?

Author: Jon Adams, 2011-11-17

6 answers

Agregue el tipo MIME JSON a IIS 6. Siga las instrucciones en Configurar tipos MIME (IIS 6.0) de MSDN.

  • Extensión: .json
  • Tipo MIME: aplicación / json

No olvide reiniciar IIS después del cambio.

ACTUALIZACIÓN: Hay formas fáciles de hacer esto en IIS7 y versiones posteriores. La op pidió específicamente ayuda de IIS6, así que dejo esta respuesta tal cual. Pero esta respuesta todavía está recibiendo mucho tráfico a pesar de que IIS6 es muy antiguo ahora. Espero que estés usando algo más nuevo, así que quería mencionar que si tienes un IIS7 más reciente o una versión más reciente, consulta la respuesta de @ProVega a continuación para obtener una solución más simple para esas versiones más recientes.

 109
Author: Jon Adams,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-12 14:52:12

Si desea agregar soporte manualmente a su sitio, solo puede agregar lo siguiente a su web.config en el sistema .Servidor web sección:

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

Esto agregará una configuración "local" bajo IIS. Esto no funciona en IIS6, pero funciona en IIS7 y versiones posteriores.

 195
Author: ProVega,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-12 14:54:42

La solución es que necesita agregar el tipo de extensión de archivo json en Tipos MIME

Método 1

Vaya a IIS, Seleccione su aplicación y Busque Tipos MIME

introduzca la descripción de la imagen aquí

Haga clic en Añadir desde el panel derecho

File Name Extension = .json

MIME Type = application / json

introduzca la descripción de la imagen aquí

Después de agregar .json tipo de archivo en Tipos MIME, Reinicie IIS e intente acceder a json file


Método 2

Vaya a la web.config de esa aplicación y añadir estas líneas en ella

 <system.webServer>
   <staticContent>
     <mimeMap fileExtension=".json" mimeType="application/json" />
   </staticContent>
 </system.webServer>
 15
Author: Kaushal Khamar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-11 10:40:33

Tuve este problema pero tuve que encontrar la configuración para IIS Express para poder agregar los tipos mime. Para mí, estaba ubicado en C:\Users\<username>\Documents\IISExpress\config\applicationhost.config y pude agregar el "mapa mime" correcto allí.

 5
Author: longda,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-22 18:11:37

Al agregar soporte para mimetype (como sugiere @ProVega), también es una práctica recomendada eliminar el tipo antes de agregarlo , esto es para evitar errores inesperados al implementar en servidores donde ya existe soporte para el tipo, por ejemplo:

<staticContent>
    <remove fileExtension=".json" />
    <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
 4
Author: Mark Cooper,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-12 08:00:00
  1. Vaya a C:\Users\username\Documents\IISExpress\config
  2. Abierto applicationhost.config con Visual Studio o su editor de texto favorito.
  3. Busca la palabra mimeMap, deberías encontrar muchas.
  4. Agregue la siguiente línea al principio de la lista: .
 0
Author: pratik godha,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-13 20:15:42