我有興趣將一些代碼移植到ASP.NET Core,並希望知道從ASP.NET Core Web服務發送文件(即「下載」文件)的最有效方式。從asp.net核心有效發送文件
和我的老ASP.NET代碼,我用一個FileStream:
var content = new FileStream(
myLocation,
FileMode.Open, FileAccess.Read, FileShare.Read);
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(content)
};
不過,我試圖找到.NET相當於FreeBSD的的sendfile(),發現HttpResponse.TransmitFile。我認爲這會更快?
我還擔心該文件將不得不在擊中用戶之前從Kestrel跳出到IIS。有什麼建議?
文件位於何處 - 文件系統或數據庫? – Win
@Win,該文件位於文件系統上。 –