另存为提示“图像名称”在通用 handler.ashx 中?
当我使用 Handler.ashx ans 显示文件夹中的图像时,然后尝试通过右键单击图像来保存图像,它会不断向我提供“另存为类型”asp.net 通用处理程序选项,并将处理程序名称作为文件名
Bitmap target = new Bitmap(width, height);
using (Graphics graphics = Graphics.FromImage(target)) {
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.DrawImage(photo, 0, 0, width, height);
using (MemoryStream memoryStream = new MemoryStream()) {
target.Save(memoryStream, ImageFormat.Png);
OutputCacheResponse(context, File.GetLastWriteTime(photoPath));
using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
{
memoryStream.WriteTo(diskCacheStream);
}
memoryStream.WriteTo(context.Response.OutputStream);
}
}
。是处理程序,
ImageTiff.ImageUrl = "Handler.ashx?p=" + Parameter;
这是后面的代码。
我需要使用图像名称而不是 handler.ashx 保存它
When i am displaying image from folder using Handler.ashx ans then try to save the image by right clicking it it keeps giving me the option of "Save as type" asp.net generic handler and the handler name as the File name..
Bitmap target = new Bitmap(width, height);
using (Graphics graphics = Graphics.FromImage(target)) {
graphics.CompositingQuality = CompositingQuality.HighSpeed;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.DrawImage(photo, 0, 0, width, height);
using (MemoryStream memoryStream = new MemoryStream()) {
target.Save(memoryStream, ImageFormat.Png);
OutputCacheResponse(context, File.GetLastWriteTime(photoPath));
using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
{
memoryStream.WriteTo(diskCacheStream);
}
memoryStream.WriteTo(context.Response.OutputStream);
}
}
above is the handler and
ImageTiff.ImageUrl = "Handler.ashx?p=" + Parameter;
this is the code behind.
I need to save it with the Image name ans not as the handler.ashx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在发送数据之前设置 ContentType 和 Content-Disposition HTTP 标头:
You should set the ContentType and Content-Disposition HTTP headers before sending your data:
睡个好觉,我猜你的帮助成功了:) 谢谢大家!
A good night sleep and your help did the trick i guess :) Thanks guys !
当您希望用户保存文件时,您需要发送“application/octet-stream”的ContentType。
这是我们使用的代码(在 vb.net 中,抱歉)(我刚刚验证了当 ashx 请求时,这确实为用户提供了正确的文件名):
C# 翻译:
When you want the user to save the file, you need to send a ContentType of "application/octet-stream".
Here is the code (in vb.net, sorry) that we use (I just verified that this does result in the correct file name for the user when requested from an ashx):
C# translation: