473,769 Members | 2,245 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
14 9505
Interesting thought. But why then does it work when served up by IIS5 (XP) and IIS6 (server2003)? This exact same
same code (and the aspx apps that use them) has been working for years on both XP and 2003.
"George Ter-Saakov" <gt****@cardone .comwrote in message news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>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 #11
Hi Brad,

You can just replace 'localhost' with your computer name and Fiddler should
be able to capture the traffic.

Here's the response header at my side (both writing the PDF using stream
and visiting directly works on my side):
Viewing pdf directly:

HTTP/1.1 200 OK
Content-Type: application/pdf
Last-Modified: Thu, 19 Apr 2007 07:15:36 GMT
Accept-Ranges: bytes
ETag: "8071d9865282c7 1:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Tue, 08 May 2007 09:31:38 GMT
Content-Length: 48148
Viewing pdf from aspx page:

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: Tue, 08 May 2007 09:30:20 GMT
As you can see the log is same as yours.

Do you have another Vista box to test? This can help to confirm if it's an
environment specific issue. If another Vista box also has this issue, this
might be related to your web application (web.config or something unknown
yet), please try this with a simple web application. In this case, if you
can trim down your web application to a smaller project (while still having
the issue), please send me a copy so that I can test it on my side.

Brad, I understand this thread is rather long now and you may have some
concerns since we still haven't find the root cause; if this is urgent for
your business, I really recommend you to use our Customer Support and
Service to better troubleshoot such issue (it's non reproducible on my
side). Please see my signature for more information.
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.

May 8 '07 #12
I am not a guru on HTTP protocols but with HTTP 1.0 the server will always
close connection which meant that transmission of the file ended. With HTTP
1.1 connection might be kept open so browser does not need to reconnect if
it needs to get the bunch of pictures from the same site (Usually that is
the case with regular HTML). Browser sends a request Connection: keep-open
(something like that) and server honors it if it can.

So server might not close it right away. If server does not response with
Content-Length and do not close connection browser have no way to know that
download has stopped.

With Fiddler it all becomes a moot point. Since Fiddler might close
connection all the time ignoring that server wanted to keep connection open.
So what I am saying you might not see clear picture with Fiddler between
browser and server.

Anyway, try to add Content-Lenght and see if it worked.

George.
"Brad" <la**@newsgroup .nospamwrote in message
news:Oh******** ******@TK2MSFTN GP03.phx.gbl...
Interesting thought. But why then does it work when served up by IIS5
(XP) and IIS6 (server2003)? This exact same same code (and the aspx
apps that use them) has been working for years on both XP and 2003.
"George Ter-Saakov" <gt****@cardone .comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>>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******* *******@TK2MSFT NGP06.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****** ********@TK2MSF TNGHUB02.phx.gb l...
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 8 '07 #13
Walter - I found a solution to this issue. As originally noted, my code I originally posted in this thread worked in
XP and win23k but not in Vista. Some minor programming changes resolve the problem. See the code example below and its
comments which note the code that was commented out and code added to make it work.

string outputFile = Path.Combine(Re portPath, Current.Session .SessionID + "." + format.ToString ());
string contentType = "applicatio n/pdf";

// commented out next two lines
// Response.ClearC ontent();
// Response.ClearH eaders();

// added next to lines Clear and Buffer = true
Response.Clear( );
Response.Buffer = true;

Response.Conten tType = contentType;

FileStream fs = new FileStream(outp utFile, FileMode.Open);
try
{
int bufferSize = System.Convert. ToInt32(fs.Leng th);
byte[] bt = new byte[bufferSize + 1];
fs.Read(bt, 0, bufferSize);
Response.Binary Write(bt);
}
catch (Exception ex)
{
throw ex;
}
finally
{
fs.Close();
}
// commented out next two lines
//Response.Flush( );
//Response.Close( );

// added next line
Response.End();
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message news:au******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Brad,

You can just replace 'localhost' with your computer name and Fiddler should
be able to capture the traffic.

Here's the response header at my side (both writing the PDF using stream
and visiting directly works on my side):
Viewing pdf directly:

HTTP/1.1 200 OK
Content-Type: application/pdf
Last-Modified: Thu, 19 Apr 2007 07:15:36 GMT
Accept-Ranges: bytes
ETag: "8071d9865282c7 1:0"
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Date: Tue, 08 May 2007 09:31:38 GMT
Content-Length: 48148
Viewing pdf from aspx page:

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: Tue, 08 May 2007 09:30:20 GMT
As you can see the log is same as yours.

Do you have another Vista box to test? This can help to confirm if it's an
environment specific issue. If another Vista box also has this issue, this
might be related to your web application (web.config or something unknown
yet), please try this with a simple web application. In this case, if you
can trim down your web application to a smaller project (while still having
the issue), please send me a copy so that I can test it on my side.

Brad, I understand this thread is rather long now and you may have some
concerns since we still haven't find the root cause; if this is urgent for
your business, I really recommend you to use our Customer Support and
Service to better troubleshoot such issue (it's non reproducible on my
side). Please see my signature for more information.
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.

Jun 7 '07 #14
Hi Brad,

Interesting, I also just came along this blog yesterday about this issue on
IIS7:

#Speaking of which... : I've upgraded and now my application doesn't work
anymore
http://blogs.msdn.com/johan/archive/...nd-now-my-appl
ication-doesn-t-work-anymore.aspx
Above blog also mentioned that we need to replace "Response.Flush () and
Response.Close( )" with Response.End() on Vista.

The code previously worked on my side is probably because I'm using IIS6
compatibility mode.
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.

Jun 8 '07 #15

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
1495
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
7610
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
2730
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
1589
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
2680
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
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
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...
1
9996
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
9865
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
8872
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
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5307
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...
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.