我有一个显示图像的ashx文件。我不想显示图像,但强制下载。
这是我的代码:
context.Response.AppendHeader("content-disposition", "attachment; filename=" + userId + ".jpg");
context.Response.ContentType = "image/jpeg";
context.Response.OutputStream.Write(msMasterFinal.ToArray(), 0, msMasterFinal.ToArray().Length); 当我用这个ashx打开我的浏览器时,图像会自动显示。如何强制下载?
非常感谢
发布于 2011-04-14 12:57:20
嗯,你的代码看起来不错。我曾经使用过这个代码片段来实现你想要做的事情:
context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=""{0}""", FileName));
context.Response.AddHeader("Content-Type", FileType);
context.Response.AddHeader("Content-Length", FileSize.ToString);
context.Response.BinaryWrite(FileBytes);它几乎是相似的..。
发布于 2011-04-15 01:35:03
如果图片是“contentType /jpeg”,你的浏览器总是会在窗口中显示图片。尝试使用不同的contentType。
https://stackoverflow.com/questions/5658674
复制相似问题