problem with pdfs

S

Scott McFadden

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
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top