在IIS7中显示二进制(pdf)内容时出现问题 [英] Problem displaying binary (pdf) content in IIS7

查看:85
本文介绍了在IIS7中显示二进制(pdf)内容时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net 2.0 Web应用程序项目,它创建一个pdf文件,将pdf保存到磁盘(水晶报告这个

部分),然后

然后我的代码读取pdf文件并将其写入httpresponse网页应用程序在win2003和xp上工作得很好而结束

结果是一个pdf文件显示在浏览器中。当我在Vista上运行相同的代码时,浏览器会显示消息

Internet Explorer无法显示网页。如果我直接从浏览器打开相同的pdf文件,它会正确显示

。如果我跟踪代码,则不会抛出任何异常。我作为IIS应用程序运行它。如果我切换到

cassini它

正常工作。

IIS7中可能导致此问题的原因是什么?

这里是代码的一个例子(并且页面源没有html内容,并且在IIS上运行的agin工作找到了

win2003和xp)


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

Dim contentType As String


contentType =" application / pdf"


使用Current.Response

如果System.IO.File.Exists(outputFile)= True则

.ClearContent()

.ClearHeaders()

.ContentType = contentType

Dim fs As FileStream = New FileStream(outputFile,FileMode.Open)

尝试

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。 HttpConte xt.Current.Trace.Warn(ex.Messa ge)

Throw ex

最后

fs.Close()

结束尝试

''################################### #####

.Flush()

。关闭()

否则

System.Web。 HttpContext.Current.Trace.Warn(未找到报告文件:; &安培; outputFile)

抛出新异常(PostExportToClient:找不到文件& outputFile)

结束如果

结束

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(folderPath, Current.Session.SessionID & ".pdf")
Dim contentType As String

contentType = "application/pdf"

With Current.Response
If System.IO.File.Exists(outputFile) = True Then
.ClearContent()
.ClearHeaders()
.ContentType = contentType
Dim fs As FileStream = New FileStream(outputFile, 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.HttpContext.Current.Trace.Warn(ex.Messa ge)
Throw ex
Finally
fs.Close()
End Try
''########################################
.Flush()
.Close()
Else
System.Web.HttpContext.Current.Trace.Warn("Report file not found: " & outputFile)
Throw New Exception("PostExportToClient: File not found " & outputFile)
End If
End With

推荐答案

嗨布拉德,


到目前为止,我对这个问题的理解是:


1)网站安装在Vista上的IIS7上

2)当您访问将下载PDF文件的网页时,您发现

它无法正常工作。 (有一件事我不清楚的是:你在IIS7或其他XP / 2003系统的同一台Vista上使用IE7

吗?那是什么?IE

版本这里涉及)

我只是尝试使用以下步骤测试它:


1)在Vista上配置并安装IIS7

2)创建一个简单的网站并使用您的代码创建一个网页

3)下载一个简单的PDF文件进行测试,例如:
http://history-matters.com/archive/pdftest.pdf

4)在Vista上安装Adobe Reader 8.0


Vista上的浏览器窗口。 />
我相信这里肯定有一些东西丢失或者这是一个特定问题的环境


真诚的,

Walter Wang (wa****@online.microsoft.com,删除''在线。'')

Micro软在线社区支持


================================== ================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。如果您使用的是Outlook Express,请确保清除

复选框工具/选项/读取:一次获取300个标题及时看到你的回复




注意:MSDN托管新闻组支持服务是针对非紧急问题

其中来自社区或Microsoft支持的初步响应

工程师可在1个工作日内完成。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,也没有授予任何权利。

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.


嗨布拉德,


你看来我的回复了吗?我的测试是否适用于您?请觉得

可以免费告诉我,如果有什么我可以提供的帮助。谢谢。

问候,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


================================= =================

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子提供按现状 ;没有保证,也没有授予任何权利。

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.


适用于localhost下的网站,但不适用于其他网站

比localhost。然而,同一站点(项目)的其余部分正常工作

。例如,aspx表单页面(具有html内容的页面)

正确显示。


Walter Wang [MSFT]" < wa **** @ online.microsoft.com写信息

新闻:lE ************** @ TK2MSFTNGHUB02.phx.gbl ...

嗨布拉德,


你看来我的回复了吗?我的测试是否适用于您?请觉得

可以免费告诉我,如果有什么我可以提供的帮助。谢谢。

问候,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


================================= =================

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子提供按现状 ;没有保证,也没有授予任何权利。

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.comwrote in message
news:lE**************@TK2MSFTNGHUB02.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.


这篇关于在IIS7中显示二进制(pdf)内容时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆