igorjrr
igorjrr

Reputation: 892

HTTP header Content Disposition filename not being respected

I have a dynamically generated file initiated by a button in my website (ASP.NET).

The output is written directly in the Response, since I can't create temporary files in the server (also, they would conflict because file names would be the same for all requests, but contents differ according to some other data on the page).

Everything works fine in IE. In Chrome, it doesn't. Chrome uses the name of the page (let's say Default.aspx) as the filename, regardless of what is in the HTTP header.

The HTTP header is:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/vnd.ms-excel
Expires: -1
Server: Microsoft-IIS/8.0
Content-Disposition: : attachment; filename=test.xls
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcSWdvci5SaWJlaXJvXERvY3VtZW50c1xURlNcRXN0aW1hdGVzIGFuZCBQcm9qZWN0aW9uc1xXZWJzaXRlXFBFUFdlYlNpdGVcRGF0YVF1ZXJ5XERlZmF1bHQuYXNweA==?=
X-Powered-By: ASP.NET
Date: Thu, 11 Dec 2014 17:05:19 GMT

Any solution on how to force Chrome to use the file name specified, instead of the name of the page?

If the only option is to redirect the user to a URL with the file name, how would you suggest the solution given that the file name is the same for everyone, but the contents should be separate (as they differ) for each request?

Thank you.

Upvotes: 1

Views: 7467

Answers (1)

brz
brz

Reputation: 6016

There are two colons after Content-Disposition. I guess you added the content-disposition header like this:

Response.Headers.Add("Content-Disposition:", "attachment; filename=test.xls")

which adds an extra colon.

Upvotes: 3

Related Questions