Force PNG to download instead of opening in browser with IIS

前端 未结 5 989
既然无缘
既然无缘 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条回答
  •  -上瘾入骨i
    2020-12-28 22:10

    As the other posters have said, you need to add the HTTP Content-Disposition header, with a value of attachment, to the HTTP response generated by IIS when serving the PNGs in question.

    Not sure what version of IIS you using are but:

    IIS6

    1. In the IIS Manager select the directory with the PNG files and open the Properties dialog
    2. Click the HTTP Headers tab.
    3. In the Custom HTTP Headers section, click Add.
    4. A dialog appears. In the "Custom-header name" field enter "Content-disposition". In the "Custom-header value field, enter "Attachment".
    5. You may have to restart IIS (iisreset)

    For IIS7:

    1. In the IIS Manager select the directory with the PNG files and select the Features view.
    2. Double-click the HTTP Response Headers item and then choose the Add option in the right-hand menu.
    3. A dialog appears. In the "Name" field enter "Content-disposition". In the "Value" field, enter "Attachment".
    4. You may have to restart IIS (iisreset)

    Alternatively, place this web.config in the folder with files:

    
    
      
        
          
            
            
          
        
      
    
    

    This should force the PNGs served from that directory to be downloadable.

提交回复
热议问题