如何强制下载特定文件

时间:2017-11-22 15:33:51

标签: c# asp.net asp.net-mvc

我有这种控制器方法,它运行良好,但它在浏览器中显示该文件,我想强行下载而不显示它,那么要改变什么?

public ActionResult DownloadFile(int id, string Url)
    {
        var b = db.Books.FirstOrDefault(s => s.Book_id == id);
        WebClient client = new WebClient();
        var fileStream = client.OpenRead(b.pdf_file);
        return new FileStreamResult(fileStream, "application/pdf");
    }

1 个答案:

答案 0 :(得分:0)

将其更改为:

return File(fileStream, "application/pdf", "MyRenamedFile.pdf");