首页 > 技术文章 > ashx byte[]下载

chengeng 2020-02-27 10:15 原文

html部分<a href="ashx?参数">

ashx部分

public override void ProcessRequest(HttpContext context)
{
this.UserID = base.BaseUserID;
this.strAttachGuid = context.Request["AttachGuid"];
byte[] bytes = Download(context);

if (bytes != null)
{
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ContentType = "application/download";
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8));
context.Response.BinaryWrite(bytes);
context.Response.Flush();
context.Response.Clear();
context.Response.End();
}
}

推荐阅读