当我尝试下载文件时,单击count递增5次,有时是6次而不是1次递增。我尝试使用Task.Delay(5000);,但它不起作用,.I我认为我可以用!ispostback方法解决它。在asp.net内核中,这个方法的等价物到底是什么?我该如何解决这个问题?
public IActionResult Download(int id)
{
var essay = _essayBussRepository.GetWithId(id);
essay.NumberOfDownloads = essay.NumberOfDownloads + 1;
Task.Delay(5000);
_essayBussRepository.Update(essay);
string fileName = essay.PdfName;
string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/w_essay_pdf/" + fileName);
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
return File(fileBytes, "application/force-download", fileName);
}发布于 2021-05-24 01:51:53
我通过变成异步解决了这个问题。
public async Task<IActionResult> Download(int id)
{
var essay = _essayBussRepository.GetWithId(id);
essay.NumberOfDownloads = essay.NumberOfDownloads + 1;
await Task.Delay(3000);
_essayBussRepository.Update(essay);
string fileName = essay.PdfName;
string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/w_essay_pdf/" + fileName);
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
return File(fileBytes, "application/force-download", fileName);
}https://stackoverflow.com/questions/67662684
复制相似问题