Automatic download start

  • Thread starter Jan Paul van de Berg
  • Start date
J

Jan Paul van de Berg

I have a piece of software that people can download and a third party
promoting that software. In order for them to be able to count the number
of downloads, I have to put a tracking code on my site. The tracking code
must be sent to the client when the user clicks the download button. At the
same time, the download must start. The download button links to this page:

- Possibility 1, server side redirect to executable
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<html>
<body>
<some iframe tracking code>
</body>
</html>
<%Response.Redirect("http://mysite.bla/myproggie.exe");%>

When I do this, the tracking code is not displayed because the redirect
happens earlier. The download does start though.

- Possibility 2: client side redirect to executable
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<script language="javascript">
function startDownload() {
location.href = "http://mysite.bla/myproggie.exe";
}
</script>
<html>
<body>
<some iframe tracking code>
<script language="javascript"> startDownload() </script>
</body>
</html>

When I do this, Windows XP SP2 users see a yellow message in the top of
their browser that the site is trying to execute a program. I don't want
that because it scares users away.

- Possibility 3: client side redirect to asp page that performs a server
side redirect
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<script language="javascript">
function startDownload() {
location.href = "http://mysite.bla/startdownload.asp";
}
</script>
<body>
<some iframe tracking code>
<script language="javascript"> startDownload() </script>
</body>
</html>

[startdownload.asp]
<%Response.Redirect("http://mysite.bla/myproggie.exe");%>

This also gives the warning in XP SP2. The strange thing is when I link the
download button directly to startdownload.asp, there's no warning.

How can I get this to work?
 
B

bruce barker \(sqlwork.com\)

you should move the tracking code logic to the server. have an aspx page do
the download:

mydownloadpage.aspx?id=<download file id>&src=<third party site id>

use Response.WriteFile and response headers to do the download. google for
more info.

-- bruce (sqlwork.com)
 
J

Jan Paul van de Berg

Thanks for the info. Unfortunately all examples I find assume you don't
have a 3rd party script but just want to force the download start. I've
tried this [1]:

<%@ Import Namespace="System.IO"%>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

Dim filepath As String = Server.MapPath("myproggie.exe")
If File.Exists(filepath) Then
Dim filename As String = Path.GetFileName(filepath)
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(filepath)
End If

End Sub
</script>

No matter what I try, I can't get mydownloadpage.aspx to send html to the
browser. Not by adding Response.Write(<3rd party script>) anywhere, not by
adding HTML. It behaves like Possibility 1 I described.

[1] a modified version of
http://www.ondotnet.com/pub/a/dotnet/2002/04/01/asp.html, all other
references to this method I can find work the same

Op Fri, 23 Jun 2006 08:56:09 -0700 schreef bruce barker (sqlwork.com):
you should move the tracking code logic to the server. have an aspx page do
the download:

mydownloadpage.aspx?id=<download file id>&src=<third party site id>

use Response.WriteFile and response headers to do the download. google for
more info.

-- bruce (sqlwork.com)

Jan Paul van de Berg said:
I have a piece of software that people can download and a third party
promoting that software. In order for them to be able to count the number
of downloads, I have to put a tracking code on my site. The tracking code
must be sent to the client when the user clicks the download button. At
the
same time, the download must start. The download button links to this
page:

- Possibility 1, server side redirect to executable
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<html>
<body>
<some iframe tracking code>
</body>
</html>
<%Response.Redirect("http://mysite.bla/myproggie.exe");%>

When I do this, the tracking code is not displayed because the redirect
happens earlier. The download does start though.

- Possibility 2: client side redirect to executable
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<script language="javascript">
function startDownload() {
location.href = "http://mysite.bla/myproggie.exe";
}
</script>
<html>
<body>
<some iframe tracking code>
<script language="javascript"> startDownload() </script>
</body>
</html>

When I do this, Windows XP SP2 users see a yellow message in the top of
their browser that the site is trying to execute a program. I don't want
that because it scares users away.

- Possibility 3: client side redirect to asp page that performs a server
side redirect
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<script language="javascript">
function startDownload() {
location.href = "http://mysite.bla/startdownload.asp";
}
</script>
<body>
<some iframe tracking code>
<script language="javascript"> startDownload() </script>
</body>
</html>

[startdownload.asp]
<%Response.Redirect("http://mysite.bla/myproggie.exe");%>

This also gives the warning in XP SP2. The strange thing is when I link
the
download button directly to startdownload.asp, there's no warning.

How can I get this to work?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top