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

Answers 1

To force a link as a download, it's probably easiest to just modify your html.

<a href="" download>Some link text.</a>

Adding the download attribute will cause the browser to download the file rather than open it (assuming html5).

Here's the w3school's description if you'd like to read more about it.

You could also try setting the MIME Type to file/download in IIS manager.

October 11, 2018 16:41 PM

Related Questions