资 源 简 介
<%@ WebHandler Language="C#" Class="DownImg" %>using System;using System.Web;public class DownImg : IHttpHandler { //图片下载功能 public void ProcessRequest(HttpContext context) { System.Net.WebResponse response = null; System.IO.Stream stream = null; string path = context.Request.Url.Query.Split(new string[] { "coverimg=" }, StringSplitOptions.RemoveEmptyEntries)[1]; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(path); response = request.GetResponse(); stream = response.GetResponseStream(); System.IO.MemoryStream memStream = Txooo.Mobile.HttpTools.CloneStream(stream); byte[] bytes = new byte[memStream.Length]; memStream.Read(bytes, 0, bytes.Length); // 设置当前流的位置为流的开始 memStream.Seek(0, System.IO.SeekOrigin.Begin); context.Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 string fileName = DateTime.Now.Ticks.ToString() ".jpg"; context.Response.AddHeader("Content-Disposition", "attachment; filename=" fileName); context.Response.BinaryWrite(bytes); context.Response.Flush(); } public bool IsReusable { get { return false; } }}