无需缓存即可从数据库显示PDF [英] Display PDF from database without caching

查看:86
本文介绍了无需缓存即可从数据库显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在用户浏览器中显示PDF,该浏览器是从我们数据库中的

二进制字段中提取的,并保持该PDF不会在

客户端上缓存电脑。我可以成功拉出PDF并使用

显示以下代码:


Response.ContentType =" application / pdf"

Response.BinaryWrite objRS(" Attachment")

其中objRS(" Attachment")是对检索到的二进制字段的引用

from the数据库。但是,我已经尝试添加几乎每个标题

已知与缓存有关,我似乎无法阻止

来自客户端缓存的PDF浏览器。然后我尝试使用

adodb.stream对象,如下所示:

set objStream = server.createObject(" ADODB.Stream")

objStream.Open

objStream.Type = 1''adTypeBinary

objStream.write objRS.fields(" Attachment")。value


Response.ContentType =" application / pdf"

Response.BinaryWrite objStream.Read()


,或多或少,我在网上找到的几个例子,

虽然大多数例子都是在文件中读取一个文件,而不是从一个文件中返回的二进制

字段数据库。这段代码给了我以下

错误:


响应对象,ASP 0106(0x80020005)

遇到未处理的数据类型。


我正在寻找一种方法来使流工作,或任何其他建议

如何在没有它的情况下向客户端显示pdf在他们的

浏览器中缓存。

解决方案



< ro * ****@gmail.com在留言中写道

news:11 ********************* @ i42g2000cwa.googlegro ups.com。 ..


我试图在用户浏览器中显示从我们数据库中的

二进制字段中提取的PDF,并保持来自

客户端计算机上的缓存的PDF。我可以成功拉出PDF并使用

显示以下代码:


Response.ContentType =" application / pdf"

Response.BinaryWrite objRS(" Attachment")

其中objRS(" Attachment")是对检索到的二进制字段的引用

from the数据库。但是,我已经尝试添加几乎每个标题

已知与缓存有关,我似乎无法阻止

来自客户端缓存的PDF浏览器。然后我尝试使用

adodb.stream对象,如下所示:

set objStream = server.createObject(" ADODB.Stream")

objStream.Open

objStream.Type = 1''adTypeBinary

objStream.write objRS.fields(" Attachment")。value


Response.ContentType =" application / pdf"

Response.BinaryWrite objStream.Read()


,或多或少,我在网上找到的几个例子,

虽然大多数例子都是在文件中读取一个文件,而不是从一个文件中返回的二进制

字段数据库。这段代码给了我以下

错误:


响应对象,ASP 0106(0x80020005)

遇到未处理的数据类型。


我正在寻找一种方法来使流工作,或任何其他建议

如何在没有它的情况下向客户端显示pdf在他们的

浏览器中缓存。



您无法通过修改

PDF已流式传输。在一天结束时,客户端看到完全相同的

字节序列。


您在标题中尝试了什么。以下内容应该可以防止缓存重新使用内容: -


Response.Expires = 0

Response.CacheControl =私人;最大年龄= 0; no-cache"


你也可以选择: -


Response.CacheControl =" private;最大年龄= 0;没有商店


你也可以使用一个负数来过期,以确保客户端的慢速

时钟不会导致正在缓存的内容。使用HTTP 1.1的浏览器

无论如何都将支持Cache-Control over Expiry date。


您如何确定正在重用缓存版本。例如,浏览器上的后面

按钮可能不受任何这些HTTP

标题的影响。



我尝试过以下标题:

response.addheader" Expires"," Mon,26 Jul 1997 05:00:00 GMT"

response.addheaderCache-Control,no-store,no-cache,

必须重新验证

response.addheaderCache- Control,post-check = 0,pre-check = 0'',

FALSE"

Response.AddHeader" Pragma",no-cache ;

Response.CacheControl =" no-cache"

Response.expires = -1


我试过了这些的各种组合也是如此。我确定它是否被缓存的方式是清除我的缓存,

加载页面,然后查看缓存 - PDF在

缓存仍在那里。我不太关心浏览器显示的是一个

缓存版本而不是最新版本,我更关心的是

隐私。这些PDF包含敏感信息。我担心有人在他们的浏览器中查看PDF,然后是其他人

走到他们的计算机并从他们的缓存中获取PDF。

这就是为什么我想知道是否可以通过流式传输PDF,如果我可以通过保存实际的PDF文件保存在它们的缓存文件夹中来支付



有趣的是,涉及两个页面 - 第一个

是gerenated HTML,显示来自

数据库的可用PDF列表。我已成功阻止此页面使用以下元标记缓存



< meta http-equiv =" Pragma" content =" no-cache"

< meta http-equiv =" Cache-Control" content =" no-cache">

< meta http-equiv =" Expires" content =" -1"


我还在这个

特定页面上添加了一个使用IIS的缓存控制:无缓存标题(实际上,所有用户点击这个目录中的页面。用户点击其中一个PDF链接,然后在新窗口中打开一个ASP页面,这是一个新的页面,即
application.pdf内容类型。浏览器窗口。显然我

不能在这个页面上放置meta标签,因为它不是HTML - 它是

二进制PDF,所以我卡住了使用HTTP标题。我将保持

实验,使用下面的具体示例,看看会发生什么。

Anthony Jones写道:


您无法通过修改

PDF的流式传输来阻止在客户端上缓存PDF。在一天结束时,客户端看到的完全相同

字节序列。


您在标题中尝试了什么。以下内容应该可以防止缓存重新使用内容:
重新使用内容: -


Response.Expires = 0

Response.CacheControl =" private;最大年龄= 0; no-cache"


你也可以选择: -


Response.CacheControl =" private;最大年龄= 0;没有商店


你也可以使用一个负数来过期,以确保客户端的慢速

时钟不会导致正在缓存的内容。使用HTTP 1.1的浏览器

无论如何都将支持Cache-Control over Expiry date。


您如何确定正在重用缓存版本。例如,浏览器上的后面的

按钮可能不会受到任何这些HTTP

标头的影响。


另一件奇怪的事情 - 如果我使用互联网查看我的缓存

explorer(tools -options - (general)选项卡,设置按钮

临时Internet文件部分) - 查看文件,然后PDF不是

那里。同样的事情是导航到C:\Documents和

设置\用户名\本地设置\临时Internet文件。但是,

这是一个特殊文件夹,实际文件存储在各种

子目录在content.ie5子目录中的文件夹Temporary

Internet Files - windows只是没有显示给你。所以相反,如果

你导航到\\computername\c


I am trying to display a PDF in the users browser that is pulled from a
binary field in our database, and keep that PDF from caching on the
client computer. I can successfully pull the PDF and display it using
the following code:

Response.ContentType = "application/pdf"
Response.BinaryWrite objRS("Attachment")

where objRS("Attachment") is a reference to the binary field retrieved
from the database. However, I have tried adding virtually every header
known to have anything to do with caching, and I cannot seem to prevent
the PDF from caching in the client''s browser. So then I tried to use
the adodb.stream object, as follows:

set objStream=server.createObject("ADODB.Stream")
objStream.Open
objStream.Type=1 ''adTypeBinary
objStream.write objRS.fields("Attachment").value

Response.ContentType = "application/pdf"
Response.BinaryWrite objStream.Read()

This follows, more or less, several examples I''ve found on the web,
although most examples are reading a file into the stream, not a binary
field returned from a database. This code gives me the following
error:

Response object, ASP 0106 (0x80020005)
An unhandled data type was encountered.

I''m looking for a way to make the stream work, or any other suggestions
on how to display the pdf to the client without it caching in their
browser.

解决方案


<ro*****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...

I am trying to display a PDF in the users browser that is pulled from a
binary field in our database, and keep that PDF from caching on the
client computer. I can successfully pull the PDF and display it using
the following code:

Response.ContentType = "application/pdf"
Response.BinaryWrite objRS("Attachment")

where objRS("Attachment") is a reference to the binary field retrieved
from the database. However, I have tried adding virtually every header
known to have anything to do with caching, and I cannot seem to prevent
the PDF from caching in the client''s browser. So then I tried to use
the adodb.stream object, as follows:

set objStream=server.createObject("ADODB.Stream")
objStream.Open
objStream.Type=1 ''adTypeBinary
objStream.write objRS.fields("Attachment").value

Response.ContentType = "application/pdf"
Response.BinaryWrite objStream.Read()

This follows, more or less, several examples I''ve found on the web,
although most examples are reading a file into the stream, not a binary
field returned from a database. This code gives me the following
error:

Response object, ASP 0106 (0x80020005)
An unhandled data type was encountered.

I''m looking for a way to make the stream work, or any other suggestions
on how to display the pdf to the client without it caching in their
browser.

You can''t prevent the caching of the PDF on the client by modifying how the
PDF is streamed. At the end of the day the client sees the exact same
sequence of bytes.

What did you try in the headers. The following should prevent a cache from
re-using the content:-

Response.Expires = 0
Response.CacheControl = "private; max-age=0; no-cache"

You could also go with:-

Response.CacheControl = "private; max-age=0; no-store"

Also you could use a negative number for expires to make sure that a slow
clock on the client doesn''t result in the content being cached. Browsers
using HTTP 1.1 will favor Cache-Control over Expiry date anyway.

How are you determining that a cache version is being re-used. The back
button on a browser for example may not be affected by any of these HTTP
headers.



I have tried the following headers:
response.addheader "Expires","Mon, 26 Jul 1997 05:00:00 GMT"
response.addheader "Cache-Control","no-store, no-cache,
must-revalidate"
response.addheader "Cache-Control","post-check=0, pre-check=0'',
FALSE"
Response.AddHeader "Pragma", "no-cache"
Response.CacheControl="no-cache"
Response.expires=-1

I''ve tried various combinations of these as well. The way I am
determining whether or not it is cached is by clearing my cache,
loading the page, and looking at the cache - the PDF is there in the
cache still there. I''m not so concerned about the browser showing a
cached version instead of the latest version, I''m more concerned with
privacy. These PDF''s contain sensitive information. I am worried
about someone viewing the PDF in their browser, then someone else
walking up to their computer and getting the PDF from their cache.
That''s why I was wondering if by streaming the PDF if I could keep it
from saving an actual PDF file in their cache folder.

The interesting thing is that there are two pages involved - the first
is gerenated HTML that shows the list of available PDF''s from the
database. I have successfully been able to prevent this page from
being cached with the following meta tags:
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="-1"

I have also added a cache-control:no-cache header using IIS on this
specific page (actually, all pages in this directory. The user clicks
one of the PDF links, and in a new window it opens the ASP page that is
application.pdf content type in a new browser window. Obviously I
can''t put meta tags on this page, because it is not HTML - it''s the
binary PDF, so I am stuck with HTTP headers. I will keep
experimenting, using your specific examples below and see what happens.
Anthony Jones wrote:

You can''t prevent the caching of the PDF on the client by modifying how the
PDF is streamed. At the end of the day the client sees the exact same
sequence of bytes.

What did you try in the headers. The following should prevent a cache from
re-using the content:-

Response.Expires = 0
Response.CacheControl = "private; max-age=0; no-cache"

You could also go with:-

Response.CacheControl = "private; max-age=0; no-store"

Also you could use a negative number for expires to make sure that a slow
clock on the client doesn''t result in the content being cached. Browsers
using HTTP 1.1 will favor Cache-Control over Expiry date anyway.

How are you determining that a cache version is being re-used. The back
button on a browser for example may not be affected by any of these HTTP
headers.


One other thing that is strange - if I look at my cache using internet
explorer (tools -options -(general tab, settings button under
Temporary Internet Files section) -View Files, then the PDF is not
there. The same thing is you navigate to C:\Documents and
Settings\username\Local Settings\Temporary Internet Files. However,
this is a special folder, and the actual files are stored in various
subdirectories in a content.ie5 subdirectory to the folder Temporary
Internet Files - windows just doesn''t show it to you. So instead if
you navigate to \\computername\c


这篇关于无需缓存即可从数据库显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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