Hi,
I'm fairly inexperienced with ASP and I'm wondering if there is a way to make a page redirect after a file download has taken place.
This is part of a system that restricts access to some files and tracks the number of downloads of a particular file.
The access control and downloading works fine but once the download is complete I want to refresh the page to show a success message etc.
Response.Write and Response.Redirect do not seem to have any effect.
I thought the issue might be that the Response buffer is 'true' but even if I try to Response.Write or Response.redirect and then flush the buffer nothing happens.
<honk>*:O)</honk>
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire
I'm fairly inexperienced with ASP and I'm wondering if there is a way to make a page redirect after a file download has taken place.
This is part of a system that restricts access to some files and tracks the number of downloads of a particular file.
The access control and downloading works fine but once the download is complete I want to refresh the page to show a success message etc.
Response.Write and Response.Redirect do not seem to have any effect.
I thought the issue might be that the Response buffer is 'true' but even if I try to Response.Write or Response.redirect and then flush the buffer nothing happens.
Code:
<!-- #include virtual="/data/functions.asp" -->
<%
Response.Expires = -1000 'Makes the browser not cache this page
Response.Buffer = True 'Buffers the content so our Response.Redirect will work
If Session("UserLoggedIn") <> "true" Then
Session("FileId")=Request.QueryString("fid")
Response.Redirect("login.asp?fid=") & Request.QueryString("fid")
ElseIf Not IsNumeric(Request.QueryString("fid")) Then
fail
Else
'download the file
fileId = Request.QueryString("fid")
Response.Write("<p>File id = " & fileId & "</p>")
'lookup the file url in the database from the fileId
open_database_connection()
sql= "SELECT url FROM files WHERE id = " & fileId & " AND published=true"
Set oRS = Server.CreateObject("ADODB.RecordSet")
Set oRS = connDatabase.execute(sql)
'if found then download the file
If Not oRS.EOF Then
Response.Write("<p>Downloading</p>")
Response.Write("<p><a href=""#"">Close this window</a></p>")
DownloadFile("/downloads/"&oRS("url"))
'Write out a success message or redirect to another page - this bit doesn't work, the script seems to stop here.
Response.Redirect("[URL unfurl="true"]http://10.0.0.116/")[/URL]
Else
'if not found then show an error message
fail
End If
End If
Sub fail
Response.Write("<p>Sorry, that file is not currently available for download.</p>")
End Sub
Sub DownloadFile(sFile)
strAbsFile = Server.MapPath(sFile)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
ContentType = "application/x-msdownload"
Response.Buffer = True
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile objFile.Path
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=""" & objFile.Name & """"
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
End If
End Sub
%>
<honk>*:O)</honk>
Earl & Thompson Marketing - Marketing Agency Services in Gloucestershire