asp.net VB.net file download handler not work prop

2020-04-30 16:19发布

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!

1条回答
We Are One
2楼-- · 2020-04-30 16:53

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
查看更多
登录 后发表回答