读书人

httphandler -会响应输出 http允许的所

发布时间: 2012-10-12 10:17:04 作者: rapoo

httphandler ------能响应输出 http允许的所有内容
1.能响应输出 http允许的所有内容

2.但是一般输出 图片,视频,输出一个文件(下载)----(普通的html还是交给aspx输出)


下载一个图片:点击一个连接--弹对话框--问是否下载

 public void ProcessRequest(HttpContext context)        {            //context.Response.ContentType = "text/html";//返回一个text的东西,也就是string            context.Response.ContentType = "image/JPEG";            context.Response.AddHeader("Content-Disposition", "attachment:filename=Hydrangeas.jpg");//这句话就是关键:出现对话框的关键            context.Response.WriteFile("Hydrangeas.JPG");                   }

<body>    <form id="form1" runat="server">       <a href="Handler2.ashx">点我啊</a>    </form></body>

读书人网 >Web前端

热点推荐