problem with pdfs

Discussion in 'ASP .Net' started by Scott McFadden, Jul 16, 2003.

  1. My aspx page code reads some custom values from the HTTP headers and then
    writes a given pdf to the output stream based upon the header values.
    Unforunately, my code causes IE to pop up an Open / Save dialog instead of
    invoking the Adobe plugin and displaying the pdf inside of I.E. Here is my
    code (file points to a valid pdf and mimetype is set to 'application/pdf')

    private void RenderFile(FileInfo file, string mimeType){

    this.Context.Response.ContentType = mimeType;

    Debug.WriteLine(this.Context.Response.ContentType);

    this.Context.Response.AddHeader("Content-Length",
    file.Length.ToString());

    byte[] buffer = new byte[1024];
    int bytesRead = -1;

    FileStream fs = new FileStream(file.FullName, FileMode.Open,
    FileAccess.Read);
    Debug.WriteLine(fs.Length);

    Stream output = this.Context.Response.OutputStream;

    int i = 0;
    while ( (bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0 ){

    output.Write(buffer, 0, bytesRead);
    }

    output.Close();
    }

    Watched the HTTP traffic through a tunnel and noticed that ASP.NET is
    tacking on a content-type of utf-8 on the response (even though my code set
    it to application/pdf).

    HTTP request
    GET /webtier/PcFileRetriever.aspx?queryStringParams omitted for brevity
    HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
    application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
    */*
    Accept-Language: en-us
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
    1.1.4322)
    Host: localhost:81
    Connection: Keep-Alive
    Cookie: ASP.NET_SessionId=dqnbdy45x0plax344a1drb55

    HTTP response
    HTTP/1.1 200 OK
    Server: Microsoft-IIS/5.1
    Date: Wed, 16 Jul 2003 19:41:41 GMT
    X-Powered-By: ASP.NET
    X-AspNet-Version: 1.1.4322
    Cache-Control: private
    Content-Type: application/pdf; charset=utf-8
    Content-Length: 12850530

    Anyone know how to properly stream the pdf file so the IE Adobe browser
    plugin displays it instead of prompting the user to save? thanks

    scott
     
    Scott McFadden, Jul 16, 2003
    #1
    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. Mike Kingscott

    Protecting PDFs with Forms Authentication?

    Mike Kingscott, Jun 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    472
    Mike Kingscott
    Jun 22, 2004
  2. spammy
    Replies:
    1
    Views:
    531
    bruce barker
    Aug 27, 2004
  3. Mainframe05
    Replies:
    0
    Views:
    374
    Mainframe05
    Sep 18, 2009
  4. HinaAsp.Net
    Replies:
    0
    Views:
    910
    HinaAsp.Net
    May 12, 2011
  5. Martin Emanuelsson
    Replies:
    7
    Views:
    139
    Hilary Cotter
    Oct 18, 2004
Loading...

Share This Page