AddHeader Content-Disposition Has no effect

Discussion in 'ASP General' started by Michael@MichaelLevy.net, Jul 6, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Patrice Guest

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

    --
    Patrice

    <> a écrit dans le message de news:
    ...
    >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
    >
     
    Patrice, Jul 6, 2006
    #2
    1. Advertising

  3. Guest

    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, 2006
    #3
  4. <> wrote in message
    news:...
    >
    > 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?
     
    Anthony Jones, Jul 6, 2006
    #4
  5. Patrice Guest

    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

    <> a écrit dans le message de news:
    ...
    >
    > 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.
    >
     
    Patrice, Jul 6, 2006
    #5
  6. Michael Guest

    Anthony Jones wrote:
    > <> wrote in message
    > news:...
    >
    > 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

    %>
     
    Michael, Jul 6, 2006
    #6
  7. Michael Guest

    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.
     
    Michael, Jul 6, 2006
    #7
  8. Michael Guest

    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
     
    Michael, Jul 6, 2006
    #8
  9. Patrice Guest

    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" <> a écrit dans le message de news:
    ...
    >
    > 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
    >
     
    Patrice, Jul 7, 2006
    #9
  10. Atul Guest

    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" <> a écrit dans le message de news:
    > ...
    > >
    > > 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
    > >
     
    Atul, Jul 7, 2006
    #10
  11. "Michael" <> wrote in message
    news:...
    >
    > 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.
     
    Anthony Jones, Jul 8, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramjee Tanguturi

    Content Disposition Problem with IE

    Ramjee Tanguturi, Nov 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,558
    Ramjee Tanguturi
    Nov 17, 2003
  2. S.Kartikeyan

    Response.AddHeader content-disposition

    S.Kartikeyan, Feb 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    3,974
    S.Kartikeyan
    Feb 6, 2004
  3. Martin Schmid

    Dynamic Content-Disposition file naming.

    Martin Schmid, May 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    535
    Martin Schmid
    May 7, 2004
  4. ben
    Replies:
    0
    Views:
    1,075
  5. Trapulo
    Replies:
    11
    Views:
    10,369
    Steven Cheng[MSFT]
    Sep 27, 2006
Loading...

Share This Page