【发布时间】:2020-06-01 07:36:27
【问题描述】:
我正在尝试从我的 MVC 项目 (asp.net core 3.1) 中获取文件
我创建了一个链接
<a asp-action="@nameof(HomeController.Download)" asp-controller="@HomeController.Name" asp-route-fileName="fileName.doc" download>FileName</a>
我创建了一个控制器
public async Task<ActionResult> Download(string fileName) {
var path = Path.Combine(_hostingEnvironment.WebRootPath, fileName);
if (!System.IO.File.Exists(path)) {
return NotFound();
}
var fileBytes = await System.IO.File.ReadAllBytesAsync(path);
var response = new FileContentResult(fileBytes, "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
FileDownloadName = fileName
};
return response;
}
在 Chrome 中我收到警告
不允许下载。启动或实例化下载的框架是沙盒的,但未设置标志“allow-downloads”。详情请见https://www.chromestatus.com/feature/5706745674465280。
按照链接,我该如何添加:
将“允许下载”添加到沙盒属性列表以选择加入
如果我单击 Microsoft Edge 中的按钮,则会下载文件
【问题讨论】: