Force download of PY files in Edge and IE

by mythofechelon   Last Updated October 11, 2018 15:00 PM

Clicking on a link to a PY file in Google Chrome downloads it as desired but doing so in Microsoft Edge and Internet Explorer simply views it.

Is this an issue with the web browsers or the web server? If the latter, how can IIS 10 be configured to always force downloads of PY files?

I have tried the following but nothing has made a difference:

  1. As per https://www.jamf.com/jamf-nation/articles/309/using-iis-to-enable-http-downloads-on-a-windows-server-2008-or-2012-file-share-distribution-point, adding the below MIME types for the extension .py:
    1a. application/octet-stream
    1b. file/download
    1c. application/x-python-code
    1d. text/x-python
  2. As per https://stackoverflow.com/questions/19404770/force-file-download-in-iis7, adding an outbound rewrite rule which resulted in the following values in the file web.config:

 

<outboundRules>
    <rule name="PY_ForceDownload" preCondition="PY_Precondition">
        <match serverVariable="RESPONSE_Content-Disposition" pattern=".*" />
        <conditions>
            <add input="{REQUEST_FILENAME}" pattern="(.*)\\([^/]+)\.py$" />
        </conditions>
        <action type="Rewrite" value="attachment; filename={C:2}.py" />
    </rule>
    <preConditions>
        <preCondition name="PY_Precondition">
            <add input="{REQUEST_FILENAME}" pattern="\.py$" />
        </preCondition>
    </preConditions>
</outboundRules>
Tags : iis iis-10


Related Questions