1 public void ProcessRequest(HttpContext context)
2 {
3 context.Response.ContentType = "text/plain";
4 string encodeFileName = HttpUtility.UrlEncode("test.txt");//国际通用防止产生乱码。生成ASCII
5 context.Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", encodeFileName));//在响应头中加上Content-Disposition,attachment表示以附件形式下载.
6 context.Response.WriteFile("test.txt");//输出文件内容
7 }
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
4 <title></title>
5 </head>
6 <body>
7 <a href="DownLoad.ashx">下载</a>
8 </body>
9 </html>
原文:http://www.cnblogs.com/clcloveHuahua/p/5161825.html