473,756 Members | 9,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem displaying binary (pdf) content in IIS7

I have a .net 2.0 web application project that creates a pdf file, saves the pdf to disk (crystal reports does this
part), and
then my code reads the pdf file and writes it to the httpresponse The web app works great on win2003 and xp and the end
result is a pdf file is displayed in the browser. When I run the same code on Vista, the browser displays the message
"Internet Explorer cannot display the web page". If I open the same pdf file directly from the browser it displays
correctly. If I trace the code no exceptions are thrown. I am running this as an IIS application. If I switch to
cassini it
works correctly.
What might cause this problem in IIS7?
Here is an example of the code (and the page source has no html content, and agin work find under IIS running on
win2003 and xp)

Dim outputFile As String = Path.Combine(fo lderPath, Current.Session .SessionID & ".pdf")
Dim contentType As String

contentType = "applicatio n/pdf"

With Current.Respons e
If System.IO.File. Exists(outputFi le) = True Then
.ClearContent()
.ClearHeaders()
.ContentType = contentType
Dim fs As FileStream = New FileStream(outp utFile, FileMode.Open)
Try
Dim bufferSize As Integer = CType(fs.Length , Integer)
Dim bt(bufferSize) As Byte
fs.Read(bt, 0, bufferSize)
.BinaryWrite(bt )
Catch ex As Exception
System.Web.Http Context.Current .Trace.Warn(ex. Message)
Throw ex
Finally
fs.Close()
End Try
'############## ############### ###########
.Flush()
.Close()
Else
System.Web.Http Context.Current .Trace.Warn("Re port file not found: " & outputFile)
Throw New Exception("Post ExportToClient: File not found " & outputFile)
End If
End With

Apr 18 '07 #1
14 9501
Hi Brad,

My understanding of the issue so far is:

1) The web site is installed on IIS7 on Vista
2) When you're visiting a web page that will download a PDF file, you found
it's not working correctly. (One thing unclear to me is: are you using IE7
on the same Vista with IIS7 or from other XP/2003 system? and what's the IE
version involved here)
I just tried to test it on my side using following steps:

1) Configured and installed IIS7 on Vista
2) Created a simple web site and created a web page using your code
3) Downloaded a simple PDF file to test, for example:
http://history-matters.com/archive/pdftest.pdf
4) Installed Adobe Reader 8.0 on Vista

It seems your code is working correctly by opening the PDF document in IE7
browser window on Vista.
I believe there must be something missing here or this is an environment
specific issue.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 19 '07 #2
Hi Brad,

Have you seem my last reply? Does my test works on your side? Please feel
free to let me know if there's anything I can help. Thanks.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 23 '07 #3
It works for a site under localhost, but not for a different web other
than localhost. However the rest of the same site (project) works
correctly. For example aspx form pages (pages that have html content)
display correctly.

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:lE******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Brad,

Have you seem my last reply? Does my test works on your side? Please feel
free to let me know if there's anything I can help. Thanks.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 30 '07 #4
It works for a site under localhost, but not for a different web other
than localhost. However the rest of the same site (project) works
correctly. For example aspx form pages (pages that have html content)
display correctly.....A nd it is the same problem with an image such as jpg.
Image display in casini and localhost, but not the other webs.
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:lE******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Brad,

Have you seem my last reply? Does my test works on your side? Please feel
free to let me know if there's anything I can help. Thanks.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 30 '07 #5
Hi Brad,

Thanks for the update.
And it is the same problem with an image such as jpg. Image display in
casini and localhost, but not the other webs.

Do you mean that if you directly visit http://localhost/website/test.jpg
also doesn't work? What's the HTTP status code returned? In my test, if you
remove .jpg from MIME types (IIS manager, configure website's MIME Types),
you will get HTTP 404.3 error code when you visit a .jpg file from the
website.

However, in your PDF case, since we're directly telling the browser that
the content/type is "applicatio n/pdf", the MIME Types settings should not
apply here. By the way, what's the error message when you visit the page
that's generating the PDF file?

Try to create a new Application from the Root directory, this will make
sure it inherits from the settings from your root directory (since you
mentioned the root application is working fine).
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 2 '07 #6
Just the opposite. If I directly vist the pdf or image url it DOES work. It only fails when the content is served up
via a asp.net page
Please note: I have created multiple webs on the vista workstation. The problem occurs on a web other than localhost.
If I use localhost all works correctly. If I use a web other that localhost, displaying the image content from an
asp.net page fails i.e. http://myotherweb/website/showimage.aspx , however accessing the image directly does work i.e.
http://myotherweb/website/test.jpg

There is no .Net error message with the error occrus (event if I step through the code no exception is raised).
Internet Explorer just shows the generic message "Internet Explorer cannot display the webpage"
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message news:fG******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Brad,

Thanks for the update.
>And it is the same problem with an image such as jpg. Image display in
casini and localhost, but not the other webs.

Do you mean that if you directly visit http://localhost/website/test.jpg
also doesn't work? What's the HTTP status code returned? In my test, if you
remove .jpg from MIME types (IIS manager, configure website's MIME Types),
you will get HTTP 404.3 error code when you visit a .jpg file from the
website.

However, in your PDF case, since we're directly telling the browser that
the content/type is "applicatio n/pdf", the MIME Types settings should not
apply here. By the way, what's the error message when you visit the page
that's generating the PDF file?

Try to create a new Application from the Root directory, this will make
sure it inherits from the settings from your root directory (since you
mentioned the root application is working fine).
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 2 '07 #7
Hi Brad,

Thanks for the update, so the showimage.aspx is writing out binary image
data just like the PDF?

Please install Fiddler (http://www.fiddlertool.com/) and capture the
request/response between the browser and the web server to compare the
difference when the page is served using localhost and a sub website. I
think the returned HTTP status code will be different.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 3 '07 #8
Fiddler does not seem capture localhost traffic (tested this on fact on several computers). It only seems to capture
from webs other than localhost. But here are the header differences between viewing the pdf directly and viewing it
from aspx page:

Viewing pdf directly (pdf does display)
HTTP/1.1 200 OK
Content-Type: application/pdf
Last-Modified: Mon, 07 May 2007 15:07:22 GMT
Accept-Ranges: bytes
ETag: "c0bf96ab990c71 :0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Mon, 07 May 2007 15:14:51 GMT
Content-Length: 55193

Viewing pdf from aspx page that writes binary content using code that started this thread (pdf does not display)
HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/pdf
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 07 May 2007 14:57:16 GMT
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message news:$2******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Brad,

Thanks for the update, so the showimage.aspx is writing out binary image
data just like the PDF?

Please install Fiddler (http://www.fiddlertool.com/) and capture the
request/response between the browser and the web server to compare the
difference when the page is served using localhost and a sub website. I
think the returned HTTP status code will be different.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


May 7 '07 #9
I believe for binary files you must output "Content-Length" in a header.
Cause otherwise browser does not know when transmission of the file stopped.

George.
"Brad" <la**@newsgroup .nospamwrote in message
news:ei******** ******@TK2MSFTN GP06.phx.gbl...
Fiddler does not seem capture localhost traffic (tested this on fact on
several computers). It only seems to capture
from webs other than localhost. But here are the header differences
between viewing the pdf directly and viewing it
from aspx page:

Viewing pdf directly (pdf does display)
HTTP/1.1 200 OK
Content-Type: application/pdf
Last-Modified: Mon, 07 May 2007 15:07:22 GMT
Accept-Ranges: bytes
ETag: "c0bf96ab990c71 :0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Mon, 07 May 2007 15:14:51 GMT
Content-Length: 55193

Viewing pdf from aspx page that writes binary content using code that
started this thread (pdf does not display)
HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/pdf
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 07 May 2007 14:57:16 GMT
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:$2******** ******@TK2MSFTN GHUB02.phx.gbl. ..
>Hi Brad,

Thanks for the update, so the showimage.aspx is writing out binary image
data just like the PDF?

Please install Fiddler (http://www.fiddlertool.com/) and capture the
request/response between the browser and the web server to compare the
difference when the page is served using localhost and a sub website. I
think the returned HTTP status code will be different.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

============== =============== =============== ======
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============== =============== =============== ======

This posting is provided "AS IS" with no warranties, and confers no
rights.



May 7 '07 #10

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

Similar topics

2
5128
by: Kubaton Lover | last post by:
I'm still having a problem with the following code, but I can better describe the symptoms now. Code: <?php $uri = getenv('REQUEST_URI'); $pieces = explode('/',$uri); $file = $pieces;
0
1493
by: Scott McFadden | last post by:
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){ ...
3
5108
by: Ipsita | last post by:
Hi! I am trying SOAP with DIME attachments in web services. For example say, I have a file resume.pdf stored somewhere on my server. How does the web service send the file to the client, so that the client can store it and also read from it. I am trying out with C# and ASP.NET. Server Side Web Method: -----------------------
7
7609
by: Jim | last post by:
I am trying to display images that are stored in a database, and I am using a repeater control. What I still use the Response.BinaryWrite method with a binding expression, if so, what with the code look like?
3
2910
by: bss2004 | last post by:
Help! I'm posting a PDF Doc to a remote server using WebClient UploadData and the following code. The DOC posts fine and the server returns a positive response. If I access the remote file in Firefox the Adobe PDF Reader in Firefox kicks off and I can view the file just fine. HOWEVER, if I try to access the file using Internet Explorer Adobe never kicks off and I receive a screenfull of text (which looks like the raw text data of the...
6
2728
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios, every now and then the client would timeout and have to re-initiate the request... TIA!
4
1473
by: GJK | last post by:
Hello, I am trying to download a pdf file using HTTPWebRequest class and then save the downloaded pdf to a SQL Server 2005 database image column and then display the pdf on a web app. When I try to display the PDF, Adobe reader comes up and shows an error msg "an uncrecognized token aID was found". Here is my code to download Dim binByte As Byte()
5
1588
by: monomaniac21 | last post by:
Hi I have uploaded a pdf file into my db and am trying to display it again here is the code i have used (at the moment it is just displaying the binary file's code as text in a html page: <?php session_start(); include("connection.php"); $query = "SELECT resource, resource_name FROM tblresources WHERE id = '3' ";
5
2679
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi, I wonder if someone could shed some light on this one for me. I have developed a web app in VS2005 with the built in server. It uses an sql database, everytihng works. I need to test it across the network, so i've installed IIS7 on my Vista machine and created a new website, point at the website's directory. After I switched to the 'Classic .net' app pool, it shows up on the port.
0
10062
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9901
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9728
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8733
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5322
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2694
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.