【问题标题】:Download file works on firefox, not on other browsers下载文件适用于firefox,不适用于其他浏览器
【发布时间】:2016-12-13 14:15:49
【问题描述】:

在暂存时,我的下载功能运行良好,当我在生产中部署(使用 IIS 7.5 的 nas 服务器)时,相同的功能仅适用于 Firefox。 使用 IE、Edge 和 Chrome 开始下载,但没有到达最后,一分钟后,出现错误。 我知道网上有很多文档,但我只是尝试了很多没有结果的解决方案。请帮帮我。

@Page Language="VB" ContentType="text/html"

@Import Namespace="System.Data"

@Import Namespace="System.Data.SqlClient"

@Import Namespace="System.IO"


Private SUB SDataBind()

    'Path construction
        Dim VarFileName as string = "mytest.zip"

    'Path construction
        Dim VarPath as string = "/public/mydownload" & VarFileName

    'Absolute path
        Dim VarCompletPath as string = Server.MapPath(VarPath)
        VarCompletPath = replace(VarCompletPath,"/","\")

    'Filename construction
        Dim VarLast4Char as string = right(VarFileName,4)
        Dim VarNewFilename as string = "download" & VarLast4Char

    'Headers cleaner
        Response.Clear
        Response.ClearHeaders
        Response.ClearContent

    'Send the file to the browser
        Response.AddHeader("Content-Disposition", ("attachment;filename=" & VarNewFilename))
        Response.ContentType = ReturnFiletype(  right(VarFileName,4)  )
        Response.WriteFile( VarCompletPath )
        Response.Flush()
        Response.Close()
        Response.End

end sub


'----------------------------

'Get content file type
Private function ReturnFiletype(fileExtension as string) as string  

    Select Case fileExtension

        case ".zip"
            return "application/zip"
        case ".pdf"
            return "application/pdf"
        case else
            return "application/octet-stream"
        end select

end function

【问题讨论】:

  • "一分钟后,得到一个错误" - 什么错误?
  • 操作取消​​

标签: asp.net vb.net download header response


【解决方案1】:

我用更经典的函数解决了

'清理标题 响应清除 Response.ClearHeaders Response.ClearContent

'发送文件到浏览器 Response.AddHeader("Content-Disposition", ("attachment;filename=" & VarFileName)) Response.WriteFile(Server.MapPath(VarPath)) 响应。结束

我删除了这些行 Response.Flush() Response.Close()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-14
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多