Force PNG to download instead of opening in browser with IIS

前端 未结 5 1005
既然无缘
既然无缘 2020-12-28 21:13

I need to be able to have a subdirectory of images all PNG\'s to be downloaded instead of opened in the browser window. I am using IIS for the web server.

Is there

5条回答
  •  梦谈多话
    2020-12-28 22:17

    Probably, my answer is outdated but hopefully it can be useful for someone...

    As the other posters have said, you need to add the HTTP 'Content-Disposition' response header.

    The problem could appear if you can't use IIS Manager and have to use command line.

    So, if you need to add this pretty HTTP response header using command line only, you can use such construction:

    %systemroot%\system32\inetsrv\APPCMD set config "Default Web Site/path/to/images" /section:httpProtocol /+customHeaders.[name='Content-disposition',value='Attachment']
    

    It will add HTTP 'Content-Disposition' response header for your '/path/to/images' folder of your 'Default Web Site'.

    This can be useful in case you do autimaticaly configuration of your IIS with a couple of scripts or BAT/CMD-files.

提交回复
热议问题