Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 下载文件适用于firefox,而不适用于其他浏览器_Asp.net_Vb.net_Download_Header_Response - Fatal编程技术网

Asp.net 下载文件适用于firefox,而不适用于其他浏览器

Asp.net 下载文件适用于firefox,而不适用于其他浏览器,asp.net,vb.net,download,header,response,Asp.net,Vb.net,Download,Header,Response,在过渡阶段,我的下载功能工作正常,当我在生产环境中部署(带有IIS 7.5的nas服务器)时,相同的功能只在Firefox上工作。 使用IE、Edge和Chrome开始下载,但下载并未结束,几分钟后,出现错误。 我知道网上有很多文档,但我只是尝试了很多解决方案,没有结果。请帮帮我 @Page Language="VB" ContentType="text/html" @Import Namespace="System.Data" @Import Namespace="System.Data.

在过渡阶段,我的下载功能工作正常,当我在生产环境中部署(带有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

我用一个更经典的函数解决了这个问题

“清理标题 回答,清楚 Response.ClearHeaders Response.ClearContent

'将文件发送到浏览器 Response.AddHeader(“内容处置”(“附件;filename=“&VarFileName)) Response.WriteFile(Server.MapPath(VarPath)) 答复.完

我把线移走了 Response.Flush()
Response.Close()

“分钟后,出现错误”-什么错误?操作已取消