Joel Martinez Joel Martinez - 1 month ago 5
ASP.NET (C#) Question

Download powershell (.ps1) file via ASP.NET

I've got a

.ps1
file that I would like to link readers to. Unfortunately, navigating to that URL only results in a 404. If memory serves, this is being "blocked" just like
.config
files, but there's a way to change that configuration in
web.config
... but I can't seem to find the correct thing via search.

TL;DR, how can I expose a
.ps1
powershell script so that it's accessible (though not executable, obviously) via HTTP.

Answer

I believe you need to add a MIME type for .ps1. In your IIS Manager, select the server node on the tree, and click "MIME Types". Then click "Add..." on the right panel. For extension, set it to .ps1, and set the MIME type to text/plain.

Now IIS should serve .ps1 files.

You could use a MIME Type of application/octet-stream instead of text/plain. Using the former will cause most browsers to download it rather than try to display it.

You can do this for a specific web application or virtual directory, too. If you are doing this through web.config, it would look something like this:

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".ps1" mimeType="text/plain" /><!-- or application/octet-stream -->
        </staticContent>
    </system.webServer>
</configuration>
Comments