Link to home
Start Free TrialLog in
Avatar of FalconUK
FalconUKFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Why is my Response.Redirect not working after a Response.Flush

I've got a script that sends a pdf to the browser for download, and then should re-direct the user to my home page.

The pdf downloads correctly but the re-direct isnt working, what am I doing wrong?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
Const adTypeBinary = 1
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")

objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile Server.MapPath("..\..\") & "\data\downloads\Profile.pdf"

Response.Buffer = True
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=Profile.pdf"
Response.AddHeader "Content-Length", objStream.Size
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
rsDocs.Close
Set objStream = Nothing

Response.Redirect("/home.asp")
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Download Test</title>
</head>

<body>
<p>Download Script</p>
</body>
</html>
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Once you stream, the redirect will never be called.

FtB
One way around this is to spawn an extra window for the stream and then to redirect the original window.

FtB
Avatar of FalconUK

ASKER

By spawn an extra window do you mean using a pop up window?
Would this be done using JavaScript in the html once the page has loaded?

How would I do that?
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cheers mate, did the trick nicely!
Glad to have helped.

Any reason for the grade of B, then?

FtB
Sorry, no offence, your answer was quite right!

I'm still quite new to all of this, is there any way I can change it?
I'll take care of it and thanks.

https://www.experts-exchange.com/Web/Web_Languages/ASP/help.jsp#hi73

Good luck with your project,

FtB