|
-
Oct 29th, 2011, 09:25 PM
#1
Thread Starter
Fanatic Member
Download Button Giving Slow Response
I have a download button on my website to download an application of mine. It works fine but I noticed people are clicking it repeatedly. The response time is a little slow after you click the button. Not that bad for me but maybe it's worse for some. In the button click sub I have the code to get the file and bring up the download window and I also have code to increment a table for download count and get the IP address of the person who clicked the button. If I just have the code necessary to do the download the download window comes up a little bit quicker. Here's my button click sub :
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'
Dim FilePath As String = Server.MapPath("~/FolderForDownload/MyApplication.exe")
Dim myfile As New System.IO.FileInfo(FilePath)
If myfile.Exists Then
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name)
Response.AddHeader("Content-Length", myfile.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.TransmitFile(myfile.FullName)
Else
Exit Sub
End If
Dim nowip As String
nowip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If nowip = "" Then
nowip = Request.ServerVariables("REMOTE_ADDR")
End If
Dim MyDownloadsIncremented As New WebServiceForDownloads()
MyDownloadsIncremented.IncrementDownloadTotal(nowip)
Response.End()
End Sub
What I've noticed is that when I had Responcse.End() before my code to get the IP address and increment my table and save the IP Address it would skip performing that code so I moved it below the code. It performs the code but I noticed that after you click the button it takes longer before you see the window pop up that asks if you want to Run or Save.
I tried putting the code to get the IP address and increment my table in a separate sub and then call the sub after Response.End() but it still doesn't perform that code unless I call that sub before Response.End().
I'd like to do everything I'm now doing but get the Do you want to Run or Save window to open sooner. I'm getting a number of people downloading my application from overseas and perhaps when it runs the code to identify the IP address it takes longer. I'm not sure but I see people clicking the download button repeatedly. My table records the exact time to the second when they clicked the download button and to take an example, there are 4 consecutive entries with the same IP address and the times are 3:28 PM for all 4 with the seconds being, 13, 15, 16, and 17.
I put a test download page on my website. When I was running in Visual Studio and using a localhost address I was seeing a big difference in how quickly the window opens after you click the download button if there's download code only versus download code with the other code. When I copied the page to my website and accessed the webpage on the internet there didn't seem to be hardly any difference.
Here's a link to the test page on my website if you want to try it out. You don't have to download anything but you can see how quickly the window opens asking if you want to run or save. There are 2 buttons on the page. One says Download Code Only and the other Download Code and Other Code.
http://www.taylorentertainment.biz/TestDownload.aspx
I just tried it out and I saw a big difference in time between the two but earlier I didn't. Sometimes I think the added code runs faster and other times slower.
Last edited by EntityX; Oct 29th, 2011 at 09:59 PM.
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 31st, 2011, 02:40 AM
#2
Re: Download Button Giving Slow Response
Hello,
Bottom line, you can't put anything after the Response.End() 
How about this...
When your download button is pushed, in the client side click event, disable the button? That way, they can't push the download multiple times. Or, rather than have the same page perform the download, redirect to another page, that handles the download?
Gary
-
Oct 31st, 2011, 10:54 AM
#3
Thread Starter
Fanatic Member
Re: Download Button Giving Slow Response
If there is a redirect that might cause some delay also I would think. For me the priority is to get the download window to open quickly. Right now I just took out the unnecessary code. I can't monitor how many downloads are happening but there shouldn't be the delay.
What if in the Button Click sub I increment a variable. Is there a way I could check if that variable was incremented once each second. It could then set the variable equal to zero and run the code to get the IP address and update the table. That would be a way of isolating the two different sections of code from each other. In a Windows Forms application you can add a Timer to a form but I don't see that option in ASP.NET. Is there a way once a webpage opens to check a variable value periodically like for instance once every second?
gep13 earlier you mentioned Google Analytics. Can Google Analytics keep track of button clicks? And if it can would it also cause a similar delay?
 Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Oct 31st, 2011, 02:40 PM
#4
Re: Download Button Giving Slow Response
Hello,
Yes, there would be an additional delay during the redirect, but that wasn't the question that you were asking. You were asking how to stop multiple downloads happening from the same IP address at the same time. These two things are not the same.
If you are doing a post to a particular page, with say a QueryString parameter, then yes, in theory, you could track this with Google Analytics. Without the additional information in the URL, there would be no way to distinguish between the initial page load, and the button click.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|