[ASP.NET MVC] Force browser to download PDF document instead of opening it.

ASP.NET MVC 強制瀏覽器下載PDF檔案,而不是從瀏覽器直接開啟PDF檔案。

public ActionResult ActionName(int id)
{
    try
    {
        string folderPath = WebConfigurationManager.AppSettings["FolderUpload"];           
        var fileSavePath = Path.Combine(folderPath, FILE_NAME);
        var cd = new System.Net.Mime.ContentDisposition
        {
            // for example foo.bak
            FileName = FILE_NAME,
            // always prompt the user for downloading, set to true if you want 
            // the browser to try to show the file inline
            Inline = false,
        };
        Response.AppendHeader("Content-Disposition", cd.ToString());
        return File(fileSavePath, FILE_TYPE);
    }
    catch (Exception)
    {
        throw;
    }
}