ashx文件的下载
页面的下载应用
<a href="HandlerDownLoad.ashx?file=07.jpg">下载</a>
HandlerDownLoad.ashx代码
public class HandlerDownLoad : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string fileName = context.Request.QueryString["file"];
context.Response.AddHeader("Content-Disposition","attachment;filename=" + context.Server.UrlEncode( fileName));
string path = context.Request.MapPath("images/upload/" + fileName);//找到路径
context.Response.WriteFile(path);
}
public bool IsReusable {
get {
return false;
}
}
}