另存为提示“图像名称"在通用handler.ashx中? [英] Save As prompt "image name" in generic handler.ashx ?

查看:56
本文介绍了另存为提示“图像名称"在通用handler.ashx中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Handler.ashx ans从文件夹中显示图像时,尝试通过右键单击来保存图像,它始终为我提供另存为类型"选项,即asp.net通用处理程序,并将处理程序名称作为文件名..

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);
        }
    }

上面是处理程序,而

ImageTiff.ImageUrl = "Handler.ashx?p=" + Parameter; 

这是背后的代码.

我需要将其保存为图像名称ans而不是handler.ashx

I need to save it with the Image name ans not as the handler.ashx

推荐答案

          context.Response.ContentType = "image/pjpeg"; 
          context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + photoName  + "\"");

          OutputCacheResponse(context, File.GetLastWriteTime(photoPath));

           context.Response.Flush();


           using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew))
           {
               memoryStream.WriteTo(diskCacheStream);
           }
            memoryStream.WriteTo(context.Response.OutputStream);

睡个好觉,你的帮助达到了我的目的:)谢谢大家!

A good night sleep and your help did the trick i guess :) Thanks guys !

这篇关于另存为提示“图像名称"在通用handler.ashx中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆