我从母版页客户端脚本 (Jquery) 请求 .ashx 页面,该脚本具有下载 PDF 文件的代码。当我调试它时,我可以看到“文件下载”代码的执行,但文件没有下载。
$.ajax({
type: "POST",
url: "FileDownload.ashx",
dataType: "html",
success: function (data) { }
} );
public class FileDownload : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string fileName = "BUSProjectCard.pdf";
string filePath = context.Server.MapPath("~/Print/");
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("Content-Disposition", "attachment; filename="+fileName);
context.Response.TransmitFile(filePath + fileName);
context.Response.End();
}