0

我正在制作 DL 链接,因此其他人无法通过共享它来 dl 相同的文件到目前为止我已经找到了这段代码

public FileResult Download()
{
    byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
    string fileName = "myfile.ext";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

它不会产生可互换的链接,我们该怎么做?

4

1 回答 1

1

试试这个例子:

public ActionResult Download()
{
    var filePath=@"c:\folder\myfile.ext";
    var fileBytes = System.IO.File.ReadAllBytes(filePath);
    var response = new FileContentResult(fileBytes, "application/octet-stream")
    {
        FileDownloadName = Path.GetFileName(filePath)
    };
    return response;
}
于 2017-05-11T08:20:48.523 回答