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

蓝咒 提交于 2019-12-02 17:17:55

问题


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:


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


来源:https://stackoverflow.com/questions/43057026/asp-net-vb-net-file-download-handler-not-work-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!