473,786 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display PDF from database without caching

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.Conten tType = "applicatio n/pdf"
Response.Binary Write objRS("Attachme nt")

where objRS("Attachme nt") 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=serve r.createObject( "ADODB.Stre am")
objStream.Open
objStream.Type= 1 'adTypeBinary
objStream.write objRS.fields("A ttachment").val ue

Response.Conten tType = "applicatio n/pdf"
Response.Binary Write 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.

Sep 29 '06 #1
14 11901

<ro*****@gmail. comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.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.Conten tType = "applicatio n/pdf"
Response.Binary Write objRS("Attachme nt")

where objRS("Attachme nt") 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=serve r.createObject( "ADODB.Stre am")
objStream.Open
objStream.Type= 1 'adTypeBinary
objStream.write objRS.fields("A ttachment").val ue

Response.Conten tType = "applicatio n/pdf"
Response.Binary Write 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.Expire s = 0
Response.CacheC ontrol = "private; max-age=0; no-cache"

You could also go with:-

Response.CacheC ontrol = "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.


Sep 29 '06 #2
I have tried the following headers:
response.addhea der "Expires"," Mon, 26 Jul 1997 05:00:00 GMT"
response.addhea der "Cache-Control","no-store, no-cache,
must-revalidate"
response.addhea der "Cache-Control","post-check=0, pre-check=0',
FALSE"
Response.AddHea der "Pragma", "no-cache"
Response.CacheC ontrol="no-cache"
Response.expire s=-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.Expire s = 0
Response.CacheC ontrol = "private; max-age=0; no-cache"

You could also go with:-

Response.CacheC ontrol = "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.
Sep 29 '06 #3
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\userna me\Local Settings\Tempor ary 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$\documents and settings\userna me\local
settings\tempor ary internet files\content.i e5\ (windows no longer
treats it as a special folder) and search all files in this directory
and subdirectory, then you will find the PDF. Maybe I am just dealing
with the fact that this is just how internet explorer works, and there
is no way to prevent the actual file from existing on the client
computer?

Sep 29 '06 #4
By the way, I have the same problem with firefox - the cache is a
little more cryptic as there is no file extension, but nevertheless,
the file is still there, and is easily renamed and accessed.

Sep 29 '06 #5

ro*****@gmail.c om wrote:
I have tried the following headers:
response.addhea der "Expires"," Mon, 26 Jul 1997 05:00:00 GMT"
response.addhea der "Cache-Control","no-store, no-cache,
must-revalidate"
response.addhea der "Cache-Control","post-check=0, pre-check=0',
FALSE"
Response.AddHea der "Pragma", "no-cache"
Response.CacheC ontrol="no-cache"
Response.expire s=-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.
How will you prevent the user from hitting the "Save" button on their
browser/reader and saving a local copy of the file?

--
Mike Brind

Sep 29 '06 #6
Mike Brind wrote:
>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.

How will you prevent the user from hitting the "Save" button
on their browser/reader and saving a local copy of the file?
Those are separate issues. Many of us work in environments where such
behavior is covered under regulatory guidelines, such as HIPAA. There can be
legitimate handling of sensitive data that involves saving files.

In any case, the OP is making an effort to safeguard that information when
the user is following his/her protection guidelines. Your question is
irrelevant.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 29 '06 #7

Dave Anderson wrote:
Mike Brind wrote:
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.
How will you prevent the user from hitting the "Save" button
on their browser/reader and saving a local copy of the file?

Those are separate issues. Many of us work in environments where such
behavior is covered under regulatory guidelines, such as HIPAA. There can be
legitimate handling of sensitive data that involves saving files.

In any case, the OP is making an effort to safeguard that information when
the user is following his/her protection guidelines. Your question is
irrelevant.
Huh? Irrelevant to what? Of course I realise it's a separate issue to
the OP's problem, but it's one I am interested in knowing the answer
to. Hence I asked the question. That's what other people are allowed
to do here. And before you say it, yes, I also realise, strictly
speaking, it's OT for this group. But then so are all the html/css etc
questions that get answered.

Sod it... I withdraw the question.

--
Mike Brind

Sep 30 '06 #8

<ro*****@gmail. comwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
I have tried the following headers:
response.addhea der "Expires"," Mon, 26 Jul 1997 05:00:00 GMT"
response.addhea der "Cache-Control","no-store, no-cache,
must-revalidate"
response.addhea der "Cache-Control","post-check=0, pre-check=0',
FALSE"
Response.AddHea der "Pragma", "no-cache"
Response.CacheC ontrol="no-cache"
Response.expire s=-1
Rather than mucking about with various headers lets just use the correct
headers for your requirement.

You want to attempt to stop the file from being cached at all. This could
be a problem for PDFs.

The correct code to acheive this is:-

Response.CacheC ontrol = "private; no-store"

This informs all proxies between the origin server and the client not to
store a copy of the resource. It also tells the client that it should not
keep a copy of the resource. (no-cache actually means keep a copy if you
want but always check back with the origin server before using it)

The problem with this, at least with IE and PDFs, is that the implementation
doesn't appear to be able to handle rendering a PDF stream directly, it
needs to map the stream in to a file so despite the http headers saying
otherwise it is stored anyway. Why it isn't deleted after it has been
finished with I don't know it ought to be possible.
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.Expire s = 0
Response.CacheC ontrol = "private; max-age=0; no-cache"

You could also go with:-

Response.CacheC ontrol = "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.

Oct 1 '06 #9
That's basically the conclusion that I had come to - there is a
Microsoft support document (several, actually) on the problem of
downloading PDF's over an SSL, but I'm not using SSL - actually, in
this particular scenario, the client may or may not use SSL (inside
the company they don't - outside they do). Anyway, I will experiment
some more with the private; no-store heading - at least now I know the
correct header - thanks.

As to the question about how do you prevent a client from just saving
the PDF - you don't, and as has been stated already, that is
irrelevant. Of course someone can just save the PDF from their browser
- that's not the concern. the concern is someone ELSE pulling from a
users cache without their knowledge. Basically I am dealing with
people's pay stubs in PDF form, so if they want to save it, fine - they
can do whatever they want with it. I just don't want people pulling
OTHER employees pay stubs from their internet caches - at home, at
work, at the library, etc, etc.
Rather than mucking about with various headers lets just use the correct
headers for your requirement.

You want to attempt to stop the file from being cached at all. This could
be a problem for PDFs.

The correct code to acheive this is:-

Response.CacheC ontrol = "private; no-store"

This informs all proxies between the origin server and the client not to
store a copy of the resource. It also tells the client that it should not
keep a copy of the resource. (no-cache actually means keep a copy if you
want but always check back with the origin server before using it)

The problem with this, at least with IE and PDFs, is that the implementation
doesn't appear to be able to handle rendering a PDF stream directly, it
needs to map the stream in to a file so despite the http headers saying
otherwise it is stored anyway. Why it isn't deleted after it has been
finished with I don't know it ought to be possible.
Oct 2 '06 #10

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

Similar topics

19
2089
by: nospammmer | last post by:
Hello group, I have a rather general but interesting inquiry that is related to PHP and I hope this is the appropriate place to post it. I'm looking for a way to improve dramatically the performance of my PHP application. The application is getting slow as it is taking more load. It is performing a very high number of queries to a database, and I believe that this is taking up most of the ressources.
5
2216
by: Mark Kirkwood | last post by:
Dear all, Here is the first installment concerning ATA disks and RAID controller use in a database server. I happened to have a Solaris system to myself this week, so took the opportunity to use it as a "control". In this post I used the ATA RAID controller merely to enable UDMA 133 for an oldish x86 machine, the effect of any actual RAID level will (hopefully) be examined subsequently.
2
2057
by: Joe Shum | last post by:
Hi All: I am pretty new at ASP.NET development. Currently I need to build a Web Server app using C# and ASP.NET to automatically and repeatly refresh data changes at fixed intervals (2 to 30 secs) occurring at the server side, and refresh them at the table fields at the Browser screen without any user intervention. Typically, the user submit to the Server URL which returns a page that has a lot of table fields in it but without any...
19
2758
by: Andy B | last post by:
Hello, Sorry for this newbish question. Briefly, my problem: ------------------ I expect the database I'm working on to reach something in the order of 12-16 Gigabytes, and I am interested in understanding as much as I can about how I can make this go as fast as possible on a linux system. I haven't run such a large database before. The nature of the database is such that
1
1345
by: Ben Fidge | last post by:
What are best practices for page output caching on pages that are dynamically generated from database tables. Our site has left-hand navigation that is comprised of dynamically generated menus of product categories. The categories are taken from several database tables which rarely change. This left-hand navigation is included on every single page in the site and as such is wrapped up in a user-control. However, when I enabled caching...
17
4895
by: shineofleo | last post by:
Here is the situation: I wrote a VB programm, which stores all the information in a single Access database file using jet engine. It worked well, however one of my customs reported that there was some problems with this programm. I checked, the log files showed that the database was corrupted. The customer told me that there no 'illegal' operation such as pull out the plug, or kill the programm via task manager... So is there any...
9
1846
by: veg_all | last post by:
I have a script that takes collects info from various websites to compile a report. However whenever I run it, my web browser waits for the script to finish ( 1 minute ) before displaying the report. But my script is outputting data every few seconds . So is there a way to make my browser display the web page every few seconds and update automatically as more data comes?
3
1955
by: phil67b | last post by:
Hello everybody, I have a page rech.php where I'm doing a multi-criteria research Ex. choose your car model, choose your country. After validation of my form, on the same page, the lines will be displayed (I put a max limitation of 500 lines). Ex. list of cars Fiat to buy in UK. A clic on a line will bring me to the display page disp.php Ex. I will clic on the car n° 5 =<a href="disp.php?
3
1594
by: DNB | last post by:
I did post this message in C# group also... I would like to know what you guys think is the best way to access data: Asp.Net session vs. Database Queries. In our application we are using asp.net tree view to display hierarchical data and when user clicks on particular node it brings up totally different page with all the asp.net controls dynamically generated.
0
10363
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
10164
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
10110
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
9961
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
8989
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...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
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();...
1
4066
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
3669
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.