c# - How to handle error with content-disposition -


How can I handle an exception that send the content-displacement header for an attachment Happens after? I am trying to generate a report on the server and trying to send it as a file, but if an exception occurs during the report immature, the error message is sent to the browser itself, Also takes the form of the contents of the file and save it as a dialog. The user can not know that there was an error in generating the report, the file has now been saved in the wrong format.

Is there a way to cancel the response with this header and redirect to the error page? Or else what else can I do to inform the user of the error?

Perhaps I could already produce the report and send the header only if there is no error, but I want the response output stream so that it does not need to be in memory.

Here's my code:

  this.Response.ContentType = "application / octet-stream"; this. answer. Adhider ("content-dispute", @ "attachment; file name =" "+ item name + @" "" "" "); this.Response.Flush (); GenerateReportTo (this.Response.OutputStream); // The exception is  

Thanks for any suggestions

This is really unique for content-dispute.

Once you start sending the response body you can not change the HTTP status. If an error occurs at this time, So the only way I got the error It is known to indicate that the connection must be closed.


Comments