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, 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, adding an outbound rewrite rule which resulted in the following values in the file web.config:


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

Related Questions