Can we use Response.Flush () instead of Response.End()

后端 未结 3 1105
醉酒成梦
醉酒成梦 2020-12-18 06:11

Response.End() generates ThreadAbortException.

Using HttpContext.Current.ApplicationInstance.CompleteRequest in place of it d

3条回答
  •  失恋的感觉
    2020-12-18 06:49

    Use the condition before download the file Response.IsClientConnected -

    if (Response.IsClientConnected)
     {
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "Application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
        Response.TransmitFile(Server.MapPath(@"yourpath" + fileName));
        Response.Flush();
        Response.Close();
      }
    

    It's working for me well after lot of struggle. I hope it works for you too.

提交回复
热议问题