We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Saving files to HTTP response fails

Hi
We have been using Aspose.Cells successfully for years, but recently our service provider installed a BIG-IP reverse proxy and now Excel downloads fails. It does not happen every time, but very frequently. Previously ISA was used for reverse proxy, and we had no such problems.

A support case was started with F5 Networks (who makes BIG-IP) and their answer is that it fails because BIG-IP resets the connection due to a HTTP protocol error. This does not cause any exceptions in logs on our servers, but the client receives an incomplete file which cannot be opened in Excel.

We are a bit at a loss as to where these protocol error comes from, but since it is Aspose that handles saving the file to the response I hope you might have some insights or previous experience with similar issues.

This is our code that saves the file to the response:

var format = FileFormatType.Excel97To2003;
workbook.Save(filnavn, SaveType.OpenInExcel, format, response, Encoding.UTF8);
HttpContext.Current.ApplicationInstance.CompleteRequest();

I see in the examples on your documentation page for the saving files that you use a Response.End() after saving .xlsx and .pdf, but not after saving .xls. Is this a typo, or does .xls require different handling for some reason?

http://www.aspose.com/docs/display/cellsnet/saving%20files#SavingFiles-object

This is a support article from F5 describing this issue:
http://support.f5.com/kb/en-us/solutions/public/5000/900/sol5922.html

Note: We are using IIS7.5 on Win2008R2




Hi,


Well, I think your issue is not concerned to Aspose.Cells component, it might be due to the behavior of the browser type in your specified environment or else. We recommend you to kindly add Response.End() method to your code at the end if it makes any difference. For your information, Aspose.Cells uses Response object in the background while retrieving the Excel spreadsheet on the client side when you use Workbook.Save() overloads involving Response object as its parameter. The issue does not seems to be related to Aspose.Cells. For confirmation, please do not involve Aspose.Cells component/APIs while retrieving the file on the client side, you should get the similar issue. You may try to replace the line of code with following:
e.g
Sample code:

/Send workbook to response/
var xSaveOptions = new XlsSaveOptions(SaveFormat.Excel97To2003);
MemoryStream tempStream = new MemoryStream();
workbook.Save(tempStream, xSaveOptions);
//You may change it accordingly if you are saving in XLSX file format
Response.ContentType = “application/vnd.ms-excel”;
Response.AppendHeader(“Content-Disposition”, “attachment; filename=out1.xls”);
Response.Flush();
Response.BinaryWrite(tempStream.ToArray());
Response.End();


Thank you.

Hi and thanks for your quick response.

This is unlikely to be a browser issue, it happens in different browsers, for a lot of different customers.

Your code suggestion is good, we will try that and see if it has any effect.

We had some problems reproducing this issue in our development environment, but after setting up a cluster using NLB, like we have in our production environment we were able to reproduce it. It seems the combination of NLB on the cluster and BIG-IP on the reverse proxy was the key, while the old combination of NLB on the cluster and ISA on the reverse proxy did not give any issues.

The fix was to change one line of code, from CompleteRequest() to Response.End() like in your code example, and everything works fine

Old code:
workbook.Save(filnavn, SaveType.OpenInExcel, format, response, Encoding.UTF8);
HttpContext.Current.ApplicationInstance.CompleteRequest();

New code:
workbook.Save(filnavn, SaveType.OpenInExcel, format, response, Encoding.UTF8);
response.End();


Thanks for the help :slight_smile:

-Rune

Hi,


Good to know that your issue is sorted out now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.