Azure网站(aspnetcore)与慢速网络客户端断开连接

时间:2018-01-29 10:00:50

标签: c# azure azure-web-sites asp.net-core-mvc-2.0

我在Azure上托管了aspnetcore网站。该网站有mvc控制器方法,可以即时下载zip实现。

这是方法的例子,一个想法非常简单:

[Authorize(Roles = Roles.Supplier)]
[HttpGet("Download/{orderId}")]
public async Task<IActionResult> DownloadAsync(int? orderId)
{
    if (orderId == null)
    {
        return NotFound();
    }

    var order = await _context.Orders.Where(w=>w.id == orderId);

    if (order == null)
    {
        return NotFound();
    }

    var filesToZip = GetFilepathInZip(order.Details);

    return new FileCallbackResult(new MediaTypeHeaderValue("application/octet-stream"),
        async (outputStream, _) =>
    {
        using (var zipArchive = new ZipArchive(new WriteOnlyStreamWrapper(outputStream), ZipArchiveMode.Create))
        {
            foreach (var kvp in filesToZip)
            {
                var zipEntry = zipArchive.CreateEntry(kvp.PathInZip, CompressionLevel.NoCompression);
                using (var zipStream = zipEntry.Open())
                using (var m = new MemoryStream())
                using (var fileStream = new FileStream(kvp.PathAtServer, FileMode.Open))
                {
                    await fileStream.CopyToAsync(zipStream);
                }
            }
        }
    })
    {
        FileDownloadName = string.Format("Archive_{0}.zip", order.Id)
    };
}

每次,当我使用慢速Wi-Fi连接进行文件下载时,与服务器的连接中断,我收到了损坏的文件。

但是通过快速LAN连接,这个问题没有发生。

在app洞察中没有问题。 我正在使用共享基础架构。

它可能是什么?

相关问题