Wednesday, 3 December 2014

Response.End() throws exception "Thread was being aborted"



Response.End() allways throws an Error this as per design.











Instead of Using Response.End() we have to Use

HttpContext.Current.ApplicationInstance.CompleteRequest();


Like this


 if (File.Exists(file))
    {
       HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
       HttpContext.Current.Response.ContentType = type;
       Response.TransmitFile(file);                       
       HttpContext.Current.ApplicationInstance.CompleteRequest();
     }

No comments:

Post a Comment