AddHeader Content-Disposition Has no effect

M

Michael

I have a IIS web site that works fine on one server but not another. I
do not know if the problem is an IIS setting or something else so I
will try to include as much detail as I have figured out so far.

Several web pages allow the user to download PDF files to be viewed or
saved locally on the user's machine, not in the browser. Those web
pages all redirect to a single ASP page with QueryString parameters
identifying the relative path to the desired file on a remote server.

The redirect URL would be something like:

download.asp?Src=Statements\2006\01\123456789

My download.asp code looks something like this:

=================================================
Dim strSourceName
Dim objDocServer

' Retrieve the path to the desired document
strSourceName = Request.QueryString("Src")

' Call remote COM+ application and retrieve document as binary stream
Set objDocServer = Server.CreateObject("DocumentServer.Application")
Set objDocServer.Document = objDocServer.getDocument(strSourceName)

With Response
.Buffer = True
.Clear
.ContentType = "application/pdf"
.AddHeader "content-disposition", "attachment; filename=test.pdf;"
.BinaryWrite(objDocServer.Document)
End With
=================================================

When I try to download a file, the browser shows the File Download
dialog asking me to Open or Save the file but it shows the File name as
"123456789" rather than "test.pdf". It also shows a blank value for the
File type. Whether I choose Open or Save the same error appears:

Internet Explorer cannot download 123456789 from <server>.
Internet Explorer was not able to open this site. The requested site is
either unavailable or cannot be found. Please try again later.

If I comment out the AddHeader line, the File type shows correctly as
Adobe Acrobat Document.

If I change the AddHeader to inline rather than attachment, I see the
binary data in the browser.

This exact code works fine on another server and I have no idea why it
will not work on this new server. What I find interesting is that the
download wants to name the file as 123456789 which comes from a part of
a QueryString value and nowhere else. Could this have something to do
with the "\" characters in the QueryString being confused as path
delimiters by IIS/ASP?

Any ideas or help are appreciated!

Michael
 
P

Patrice

Also what if you try to remove the ";" after the filename in the content
disposition header ?
 
M

Michael

Patrice said:
Also what if you try to remove the ";" after the filename in the content
disposition header ?

That makes no difference. I originally did not have the semi-colon but
added it after seeing such in an example. Either way, it works on one
environment but not another.
 
A

Anthony Jones

That makes no difference. I originally did not have the semi-colon but
added it after seeing such in an example. Either way, it works on one
environment but not another.

Have you tried using a URL that doesn't have \ in the query string?
Have you tried escaping the \ as %5C ?
Are the two servers on the same OS and at the same service pack?
Have checked that are no additional headers being added by the page or
folder properties?
 
P

Patrice

What if you do simple test without anything on the query string. Something
as simple as :

With Response
.Buffer = True
.Clear
.ContentType = "text/plain"
.AddHeader "content-disposition", "attachment; filename=test.txt"
.Write("Hello world")
End With

If it works wihtout but don"t with, then it's definitively the querystring.
If the qs make this fails, try with and without path chars (or just try
right now to encode as sugested by Anthony). With those combinations, you
should able to find out what causes the problem.
 
M

Michael

Anthony said:
Have you tried using a URL that doesn't have \ in the query string?
Have you tried escaping the \ as %5C ?
Are the two servers on the same OS and at the same service pack?
Have checked that are no additional headers being added by the page or
folder properties?

Both servers are running Windows 2000 Advanced Server / Serivce Pack 4

I don't know what you mean by "headers being added by the page or
folder properties". Can you explain what this is and how I would check?

I tried another test case with no query string and get the same
results. The complete code of my new download.asp follows. It merely
writes out a local pdf file as a binary stream.

<%

Const adTypeBinary = 1
Dim strFilePath

strFilePath = Server.MapPath("my.pdf") 'This is the path to the file on
disk.

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

With Response

'Build the Response header
.Buffer = True
.Clear
.ContentType = "application/pdf"
.AddHeader "content-disposition", "filename=my.pdf;"

'Write the binary stream to the browser
.BinaryWrite objStream.Read
.End

End With

objStream.Close
Set objStream = Nothing

%>
 
M

Michael

Let me clarify when I said I get the same results without the query
string. Now the download wants to name the file "download.asp" but I
get the same error message when I click Open or Save.
 
M

Michael

Patrice said:
What if you do simple test without anything on the query string. Something
as simple as :

With Response
.Buffer = True
.Clear
.ContentType = "text/plain"
.AddHeader "content-disposition", "attachment; filename=test.txt"
.Write("Hello world")
End With

If it works wihtout but don"t with, then it's definitively the querystring.
If the qs make this fails, try with and without path chars (or just try
right now to encode as sugested by Anthony). With those combinations, you
should able to find out what causes the problem.

Hi Patrice,

I just tried that and I still get the same results. I saved that code
in a file named test2.asp. When I go to that ASP page, it displays the
File Download dialog indicating it is trying to download a file named
test2.asp with no file type specified and I get the same error message
as always.

I am sure this is not a code problem but something on the server
settings.

Michael
 
P

Patrice

Do you have something special in the IIS log for those requests ? Being able
to see the whole server response using XMLHTTP or a network tool may also
help.

Do you have a firewall ?

Good luck.
 
A

Atul

Check out the IEWatch tool. It gives you plenty of information about
the Request and Response as handled by the IE Web Browser. Not sure if
something similar is availble for other browsers but this will be
surely helpful.
Here's the URL

http://www.iewatch.com/downloads.aspx

Unfortunately it's not a freeware. :)
 
A

Anthony Jones

Michael said:
Hi Patrice,

I just tried that and I still get the same results. I saved that code
in a file named test2.asp. When I go to that ASP page, it displays the
File Download dialog indicating it is trying to download a file named
test2.asp with no file type specified and I get the same error message
as always.

I am sure this is not a code problem but something on the server
settings.

Michael

As Patrice has pointed out the next step is to examine/compare exactly what
the servers are sending to the client.

By far the best free tool for this job is:-

http://www.fiddlertool.com/fiddler/

Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top