I am trying to update a Razor page (running on IIS 10.0 version 1809) to allow me to share a Powershell script. I want the user to be able to right-click the link and select "save" to download the script from a folder on the web server (wwwroot/<site name>/downloadFiles). I verified that the NTFS permissions allow "Read & Execute", "List folder contents", and "Read" to IUSR, Network Service, Users, and IIS_IUSRS.
I tested:
In _Layout.cshtml, I have the link setup as:
<a href="~/downloadFiles/script.ps1">Script</a>
Any idea how I can make this work?
Use the FileExtensionContentTypeProvider
to map the .ps1
extension to the application/octet-stream
mime type to force a download as explained in the docs: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files#fileextensioncontenttypeprovider
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".ps1"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.