前端调用
window.location.href = "192.168.100.18/OutExcel/YJZHStatistics.ashx?code=" + code + "&Token=" + token + "&filename=" + filename + "&browserType=" + browserType;
public void ProcessRequest(HttpContext context) { string guid = HttpContext.Current.Request.Params["guid"]; string browserType = HttpContext.Current.Request.Params["browserType"]; string filename = ""; byte[] bytes; //将excel转成byte context.Response.Clear(); context.Response.ContentType = "application-excel"; if (browserType == "fireFox") { context.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlDecode(filename, System.Text.Encoding.UTF8) + ".xlsx"); } else { context.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ".xlsx"); } HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); HttpContext.Current.Response.Charset = "UTF-8"; context.Response.BinaryWrite(bytes); context.Response.Flush(); context.Response.Close(); }