Stumped - page executes twice sometimes (even thrice occasionally!)

M

Manny

I have a web form "Page1.asp" and it reads data from a database, does some
calculations, and displays the records in pages. Works fine.

I have a button that displays on the page, defined as <input type="button"
onClick="OutputData()">

The OutputData() function is a javascript function that simply does this:

window.location = "Page1.asp?Flag=1";

This "re-executes" Page1.asp, but with a flag set in the query string. The
logic in Page1.asp writes the data to a file when this flag is set instead
of paging it to the browser - it sends NOTHING to the browser when that flag
is set.

At the end of the data file generation, Page1.asp does a Response.Redirect
to Page2.asp, passing it the filename in the query string.

Page2.asp uses a COM object (DLL) we wrote in VB6 to further manipulate the
data and the end result is a PDF file that gets sent to the browser through
Response.BinaryWrite from an ADO binary stream. Page2.asp outputs no HTML
itself - only the PDF data.

What has me stumped is that Page2.asp is executing _multiple times_.
Usually it executes twice, but sometimes it executes 3 times. I can tell
because the COM object it uses writes some info to a log file. I clear the
log file, click on the button on Page1.asp _one_ time, and the log shows the
COM object being executed 2 or 3 times in a row. I cannot figure out why.
There are no loops in Page2.asp - it is a fairly simple ASP script, no
functions or sub's - just about 20 lines of script.

Page1.asp is definitely not redirecting to it multiple times. I put some
code in Page1.asp to log a timestamp each time it redirects to Page2.asp and
it only does it *once* after I click the button.

I put some code in Page2.asp to increment a Session variable and it does
increment it multiple times after a click, so it is definitely Page2.asp
that is executing multiple times. I did the same in Page1.asp and it
increments only one time per click.

Any ideas why this might be happening?
 
J

JJ

Ken,

I checked the logs and it looks like the browser (or something in between)
is doing it twice:

2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
/virtualdir/Page1.asp
ReportID=734&viewid=226&title=Job%20List&RunTimeCriteria=&Flag=1 302
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
/virtualdir/Page2.asp
Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
2003-08-29 12:57:37 192.168.1.95 username 192.168.1.11 80 GET
/virtualdir/Page2.asp
Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)

The first line is where Page1.asp is requested (by the window.location="" in
the javascript code executed on the OnClick event for the button).

The second line is the page requested by the Response.Redirect by Page1.asp.

The third line is a duplicate of the second request - I don't know why that
is showing up.

I don't discount that it could be a logic error, but I would be suprised -
there is only one Response.Redirect in Page1.asp and none in Page2.asp -
looking at the code, I can imagine what could possibly even cause that even
if I wanted to do it on purpose.
 
K

Ken Schaefer

Looking at that, it doesn't look like a logic error - it definately looks
like the browser is sending two identical requests, about 2 seconds apart.
The question is "why?" :)

I assume there's no proxy? Also, check the HTTP status for the duplicate
requests - are they both 200 (HTTP OK?). Maybe PDF files are causing the
browser to go back to the server or something?

(I'll admit that I'm a bit stumped!)

Cheers
Ken


: Ken,
:
: I checked the logs and it looks like the browser (or something in between)
: is doing it twice:
:
: 2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
: /virtualdir/Page1.asp
: ReportID=734&viewid=226&title=Job%20List&RunTimeCriteria=&Flag=1 302
: Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
: 2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
: /virtualdir/Page2.asp
: Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
: Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
: 2003-08-29 12:57:37 192.168.1.95 username 192.168.1.11 80 GET
: /virtualdir/Page2.asp
: Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
: Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
:
: The first line is where Page1.asp is requested (by the window.location=""
in
: the javascript code executed on the OnClick event for the button).
:
: The second line is the page requested by the Response.Redirect by
Page1.asp.
:
: The third line is a duplicate of the second request - I don't know why
that
: is showing up.
:
: I don't discount that it could be a logic error, but I would be suprised -
: there is only one Response.Redirect in Page1.asp and none in Page2.asp -
: looking at the code, I can imagine what could possibly even cause that
even
: if I wanted to do it on purpose.
 
J

JJ

I do think it has something to do with the PDF files.

If I remove the two lines that "cause" it to be a PDF:

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

Then it does not request the page twice. Of course, I need it to be a
PDF...

I have another version that spits out HTML with a ContentType of
"application/vnd.ms-excel" to start Excel and that doesn't request the page
twice.
 
J

JJ

I checked around and apparently this is an issue with PDF's causing 2 or 3
requests to be sent.
 
K

Ken Schaefer

That's what I'm beginning to think - perhaps the Adobe Acrobat Reader on the
client issues a second request back to the server or something...

Maybe you could alter the way your app works, so that the PDF is saved to
the filesystem (on page2.asp), and then you Response.Redirect() to page3.asp
which loads, and streams the PDF back to the client (obviously you'd then
need some code, either on the page, or as part of some clean-up function to
clean up all the old temporary PDF files). That way, even if there were
multiple requests for the PDF file, it wouldn't really have any impact.

Cheers
Ken

: I checked around and apparently this is an issue with PDF's causing 2 or 3
: requests to be sent.
:
: : > I do think it has something to do with the PDF files.
: >
: > If I remove the two lines that "cause" it to be a PDF:
: >
: > Response.ContentType "application/pdf"
: > Response.BinaryWrite objStream.Read(1)
: >
: > Then it does not request the page twice. Of course, I need it to be a
: > PDF...
: >
: > I have another version that spits out HTML with a ContentType of
: > "application/vnd.ms-excel" to start Excel and that doesn't request the
: page
: > twice.
: >
: > : > > Looking at that, it doesn't look like a logic error - it definately
: looks
: > > like the browser is sending two identical requests, about 2 seconds
: apart.
: > > The question is "why?" :)
: > >
: > > I assume there's no proxy? Also, check the HTTP status for the
duplicate
: > > requests - are they both 200 (HTTP OK?). Maybe PDF files are causing
the
: > > browser to go back to the server or something?
: > >
: > > (I'll admit that I'm a bit stumped!)
: > >
: > > Cheers
: > > Ken
: > >
: > >
: > > : > > : Ken,
: > > :
: > > : I checked the logs and it looks like the browser (or something in
: > between)
: > > : is doing it twice:
: > > :
: > > : 2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
: > > : /virtualdir/Page1.asp
: > > : ReportID=734&viewid=226&title=Job%20List&RunTimeCriteria=&Flag=1 302
: > > :
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
: > > : 2003-08-29 12:57:35 192.168.1.95 username 192.168.1.11 80 GET
: > > : /virtualdir/Page2.asp
: > > : Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
: > > :
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
: > > : 2003-08-29 12:57:37 192.168.1.95 username 192.168.1.11 80 GET
: > > : /virtualdir/Page2.asp
: > > : Fn=C%3A%5CClientData%5Ctemp%5Crad5BCDC.tmp&Title=Job%20List 200
: > > :
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.0;+.NET+CLR+1.0.3705)
: > > :
: > > : The first line is where Page1.asp is requested (by the
: > window.location=""
: > > in
: > > : the javascript code executed on the OnClick event for the button).
: > > :
: > > : The second line is the page requested by the Response.Redirect by
: > > Page1.asp.
: > > :
: > > : The third line is a duplicate of the second request - I don't know
why
: > > that
: > > : is showing up.
: > > :
: > > : I don't discount that it could be a logic error, but I would be
: > suprised -
: > > : there is only one Response.Redirect in Page1.asp and none in
: Page2.asp -
: > > : looking at the code, I can imagine what could possibly even cause
that
: > > even
: > > : if I wanted to do it on purpose.
: > >
: > >
: >
: >
:
:
 
M

Michael D. Kersey

Manny said:
I have a web form "Page1.asp" and it reads data from a database, does some
calculations, and displays the records in pages. Works fine.
I have a button that displays on the page, defined as <input type="button"
onClick="OutputData()">
The OutputData() function is a javascript function that simply does this:
window.location = "Page1.asp?Flag=1";
This "re-executes" Page1.asp, but with a flag set in the query string. The
logic in Page1.asp writes the data to a file when this flag is set instead
of paging it to the browser - it sends NOTHING to the browser when that flag
is set.
At the end of the data file generation, Page1.asp does a Response.Redirect
to Page2.asp, passing it the filename in the query string.
Page2.asp uses a COM object (DLL) we wrote in VB6 to further manipulate the
data and the end result is a PDF file that gets sent to the browser through
Response.BinaryWrite from an ADO binary stream. Page2.asp outputs no HTML
itself - only the PDF data.
What has me stumped is that Page2.asp is executing _multiple times_.
Usually it executes twice, but sometimes it executes 3 times. I can tell
because the COM object it uses writes some info to a log file. I clear the
log file, click on the button on Page1.asp _one_ time, and the log shows the
COM object being executed 2 or 3 times in a row. I cannot figure out why.
There are no loops in Page2.asp - it is a fairly simple ASP script, no
functions or sub's - just about 20 lines of script.
Page1.asp is definitely not redirecting to it multiple times. I put some
code in Page1.asp to log a timestamp each time it redirects to Page2.asp and
it only does it *once* after I click the button.
I put some code in Page2.asp to increment a Session variable and it does
increment it multiple times after a click, so it is definitely Page2.asp
that is executing multiple times. I did the same in Page1.asp and it
increments only one time per click.
Any ideas why this might be happening?

Instead of describing of what you *believe* the code does, please post
the code itself. That way we might be able to determine *what the code
actually does* and how to correct the problem.
 
M

Manny

I did a groups.google.com search on "Content-Type: application/pdf twice"
and there are numerous posts of exactly the same problem, so it is Acrobat
that is doing it (or at least the combination of Acrobat and IE).

Your suggestion sounds like it might work - I'll have to give it a try.
Page3.asp must delete the generated PDF after it is streamed to the
browser - while I probably could have something set up that cleaned up the
PDF's every hour or so, trying to get approval for that to be implemented is
a little tougher.

I'm not sure what's going to happen if Page3.asp streams the PDF, then
deletes it. The second request for Page3.asp will see that the PDF file is
gone and do nothing, but the question is what really is being displayed in
the browser - is it the stream from the first request or the stream from the
second request (my bet is the second, which blows away that idea). Although
I'd be curious to know why Acrobat throws away the first stream if that is
the case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top