如何允许Powershell从.net核心MVC Web应用程序下载EXE? [英] How to allow powershell to download an EXE from a .net core MVC web app?

查看:42
本文介绍了如何允许Powershell从.net核心MVC Web应用程序下载EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net核心MVC Web应用程序,该应用程序依赖于.net框架控制台应用程序.构建Core应用程序时,控制台应用程序也是如此,我在bin目录中获得了 exe :

I have a .net core MVC web app that depends on a .net framework console app. When the Core app builds, so too does the console app and I get the exe in the bin directory:

这很好用,但是现在我需要通过Web应用程序提供一个端点,该端点允许任何人下载EXE(目的是允许Powershell脚本通过端点下载exe).

This is working great, however now I need to provide an endpoint through the web app that allows anyone to download the EXE (the intent is to allow a powershell script to download the exe via an endpoint).

如何实现?

我了解以下信息可用于实际下载文件:

I understand the following can be used to actually download the file:

Invoke-WebRequest http://localhost:8080/download/tokenizer.exe -OutFile c:\download\tokenizer.exe

但是我不知道如何获取 exe .我相信我需要将EXE从 bin 移到某个目录,然后将其配置为可公开访问,但是我对这里的细节一无所知.

However I don't know how to get the exe accessible. I believe I need to move the EXE from the bin to some directory that I then configure as being publicly accessible, but I'm lost on the details here.

推荐答案

默认情况下,ASP.NET Core静态文件中间件将仅提供其能够理解的内容类型.未知文件类型将返回404.

By default ASP.NET Core static files middleware will only serve content types that it understands. Unknown file types will return a 404.

可以将中间件配置为服务未知文件类型,但是显式添加自己的内容类型更安全:

The middleware can be configured to serve unknown file types, however it is safer to add your own content types explictly:

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".exe"] = "application/vnd.microsoft.portable-executable";
app.UseStaticFiles(new StaticFileOptions
    {
        ContentTypeProvider = provider,            
    });

这篇关于如何允许Powershell从.net核心MVC Web应用程序下载EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆