473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

AddHeader Content-Disposition Has no effect

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

Jul 6 '06 #1
10 4594
Also what if you try to remove the ";" after the filename in the content
disposition header ?

--
Patrice

<Mi*****@MichaelLevy.neta écrit dans le message de news:
11*********************@75g2000cwc.googlegroups.co m...
>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

Jul 6 '06 #2

Patrice wrote:
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.

Jul 6 '06 #3

<Mi*****@MichaelLevy.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
>
Patrice wrote:
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.
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?

Jul 6 '06 #4
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.

--
Patrice

<Mi*****@MichaelLevy.neta écrit dans le message de news:
11*********************@75g2000cwc.googlegroups.co m...
>
Patrice wrote:
>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.

Jul 6 '06 #5

Anthony Jones wrote:
<Mi*****@MichaelLevy.netwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...

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

%>

Jul 6 '06 #6
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.

Jul 6 '06 #7

Patrice wrote:
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.

--
Patrice
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

Jul 6 '06 #8
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.
--
Patrice

"Michael" <Mi*****@MichaelLevy.neta écrit dans le message de news:
11**********************@m73g2000cwd.googlegroups. com...
>
Patrice wrote:
>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.

--
Patrice

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

Jul 7 '06 #9
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. :)

Patrice wrote:
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.
--
Patrice

"Michael" <Mi*****@MichaelLevy.neta écrit dans le message de news:
11**********************@m73g2000cwd.googlegroups. com...

Patrice wrote:
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.

--
Patrice
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
Jul 7 '06 #10

"Michael" <Mi*****@MichaelLevy.netwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Patrice wrote:
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.

--
Patrice

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.
Jul 8 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jonathan.beckett | last post by:
Hi All, For the past few months I have been working on an open source Apache/PHP/MySQL content management system - and have recently made it available for download. It's still very much a...
0
by: jonathan.beckett | last post by:
Hi All, I have just made version 0.4.8 of the PluggedOut CMS Content Management System available for download - it's free, and covered by the GPL. It's still very much a work in progress...
2
by: Robert Mark Bram | last post by:
Hi All! Does this mean the page will never cache: Response.ExpiresAbsolute = Now() - 1; Assuming this is in a login page, what effect does this have? Rob :)
0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
3
by: Craig Haywood | last post by:
Hi there, Can anyone please give me an actual example in code on how to add a header for the "HTTP/1.1 202 (Accepted)" response code I have searched the web high and low and all I can find is...
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
7
by: Rick | last post by:
I am trying to add a new header to the HTML when a webform loads. But it does not seem to work. I need to get this working in a Sharepoint webpart so adding it to the HTML page is not an option. ...
1
by: Incorrect filenames in download link. | last post by:
Hi experts, I am giving filename as "clearbenefits.infosys.txt" to Response.AddHeader as filename parameter. After clicking the download link filename on dialogbox is showing as...
8
by: Tony | last post by:
I've searched the web & can't find an answer to this. Is it possible to successfully use Response.AddHeader for a robots meta tag? For example, I want to do <% IF request("PageID") = 252...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.