I have an ashx file with IHttpHandler. When I send some data to this IHttpHandler, I do some work, create a file, and then want this file to be returned to the user so that he can save the file through the browser.
With the created file, I will try to write the file back to the response:
HttpResponse response = context.Response;
response.ClearContent();
response.Clear();
response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "attachment; filename=MYFILE.EXT");
response.WriteFile("C:\tempstuff\MYFILE.EXT");
In the last block, later I will call:
response.End()
When I call this handler, nothing happens. The 200 response is returned, no errors are generated, but the browser will not ask the user to save this file.
Here is what the answer received from Fiddler is as follows:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 23 Aug 2012 12:12:19 GMT
X-AspNet-Version: 4.0.30319
Content-Disposition: attachment; filename=MYFILE.EXT
Cache-Control: private
Content-Type: application/octet-stream
Content-Length: 781053
Connection: Close
[raw content of the file here]
This answer looks right to me. It contains the contents of the file - however, in any of the main browsers, the file dialog does not offer me to save the file.
What am I doing wrong here?
: , , JavaScript - HttpHandler.
$.ajax({
type: 'POST',
url: ashxUrl,
data: postData,
success: function (result) {
},
error: function (error) {
}
});