1

I have big file (about 2GB) to distribute to our customer, My website is written by asp.net vb, this is my file download handler:

Public Class FileHandler
    Implements IHttpHandler
    Public Sub ProcessRequest(ByVal httpcontext As HttpContext) Implements IHttpHandler.ProcessRequest
        If HttpContext.User.Identity.IsAuthenticated Then
            Dim FileName As String = HttpContext.Request.QueryString("File")            
            HttpContext.Response.Buffer = False
            HttpContext.Response.Clear()
            HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" & FileName)
            HttpContext.Response.ContentType = "application/exe"
            HttpContext.Response.TransmitFile("~/download/ExE/" & FileName)
            HttpContext.Response.Flush()
            HttpContext.Response.Close()            
        End If
    End Sub
    Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class

My problem is this handler sometimes could not work properly. Most customer could download it by this handler, but some customer click the download link, it will endless waiting for server's response, after long time waiting, it shows the error page says the IE cannot display the webpage. some customer try to download the file from IE8, it will show the error page directly. I am really appreciate any one can help with this issue. Thank you!

Maxime.Pan
  • 13
  • 1
  • 4
  • 2GB - I think that's going to be too big to be practical. Why not put the file in Dropbox and send a link to your customer ? – sh1rts Mar 27 '17 at 21:55
  • What if you change `Reponse.Close()` to `Response.End()`? – Ryan Mendoza Mar 28 '17 at 02:44
  • When I use this handler to download small file (100MB), it works very well, so could someone tell me is there any limitation of the response.transmitFile? – Maxime.Pan Mar 28 '17 at 13:51
  • Sounds like it's just timing out... IIS tracks a limit on how long you can spend processing a request before it just kills it. Browsers do the same thing. It takes a long time to transfer a 2GB file, and you're likely bumping up against that limit. – Joel Coehoorn Mar 29 '17 at 03:58
  • @JoelCoehoorn, I totally agree with you, could you give me some advices for this limit? I need to configure which part of IIS? I am using Win2012 R2 + IIS 8.5 – Maxime.Pan Mar 29 '17 at 11:38

1 Answers1

4

I use a button or just a plain link to the file itself, I've never had to use a handler to download files.

For example, on the aspx I have a button and in the code behind I send the user to the file using the response object:

Protected Sub Button_DownloadFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_DownloadFile.Click

    Response.AddHeader("Content-Disposition", "attachment; filename=TheFileName.ext")
    Response.WriteFile("~/App_Data/TheFileName.ext")

END SUB
Prescott Chartier
  • 1,519
  • 3
  • 17
  • 34
  • I have been used Response.WriteFile method before, but since my file is 2GB, so the server need long time to buffering the file and when it buffering the file, the usage of server's RAM always goes to very high, so the client need almost 10 seconds to wait for the download start. After I change to Response.TransmitFiles method, it better than before, but still has some problems. – Maxime.Pan Mar 29 '17 at 11:35
  • I've had users download >2gb files. Never had an issue with server buffering. What version of Windows are you using? I use Windows Server 2008 R2. – Prescott Chartier Mar 29 '17 at 11:47
  • My environment is Windows 2012 R2 + IIS 8.5, will be very appreciate if you can provide any suggestion about how to optimise the IIS – Maxime.Pan Mar 29 '17 at 12:23
  • For large files like that I just put up a link to the file. Similar to http://www.myserver.com/folder/filename.ext. Browser starts the download immediately and I've never observed an issue on the server side. No special configuration, default install of Windows server on a Dell 2950 server with 32gb or ram. – Prescott Chartier Mar 29 '17 at 12:28
  • my scenario is to authorize the user before they start to download, so I need to use the filehandler but to send them the real link of the file. – Maxime.Pan Mar 29 '17 at 12:31
  • For that I use Windows authorization, I set the folder properties only to let certain users access files and in IIS set the folder to use Windows Auth (or some such, writing this off the top of my head) add the users to the system and when the user clicks the link, the browser requests the username and password. I don't do this often so I don't spend a lot of time doing anything special. If it takes the user 1000 hours to download the file, I figure that's their problem :), I've just never had an issue on the server side. – Prescott Chartier Mar 29 '17 at 12:36