在通用handler.ashx中另存为"图像名称"?

Fhd*_*raf 4 c# asp.net image handle

当我使用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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

上面是处理程序和

ImageTiff.ImageUrl = "Handler.ashx?p=" + Parameter; 
Run Code Online (Sandbox Code Playgroud)

这是背后的代码.

我需要使用Image name ans而不是handler.ashx来保存它

dri*_*iis 5

您应该在发送数据之前设置ContentType和Content-Disposition HTTP标头:

context.Response.ContentType = "image/png";
context.Response.Headers["Content-Disposition"] = "attachment; filename=yourfilename.png";
Run Code Online (Sandbox Code Playgroud)