我有兴趣将一些代码移植到 ASP.NET Core,并想知道从 ASP.NET Core Web 服务发送文件(也称为“下载”文件)的最有效方式。
使用我的旧 ASP.NET 代码,我使用的是 FileStream:
var content = new FileStream(
myLocation,
FileMode.Open, FileAccess.Read, FileShare.Read);
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(content)
};
但是,我试图找到 FreeBSD 的 sendfile() 的 .NET 等效项并找到HttpResponse.TransmitFile。我认为这会更快?
我还担心该文件必须在访问用户之前从 Kestrel 到 IIS 进行额外的跳跃。有什么建议吗?