【发布时间】: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