我想要建立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);
}
它不会建立可互换的链接,我们怎么能这样做?
答案 0 :(得分: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;
}