这是一个asp.net 3.5 网站。
文件可以在 IE/FF 中正确下载。但不是铬。
该文件以“ASPS_Page_Name.aspx”的形式下载。
但是,在我将我的 chrome 浏览器更新到 20.0.1132.47 m 之前它就可以工作了。
我有这个功能可以过滤掉MIME类型(针对ff,之前的chrome不需要这个功能)
Private Shared Function GetContentType(ByVal fileType As String) As String
Select Case fileType
'set to "application/vnd.ms-excel" MIME type for firefox
'MIME Types for IIS
Case "xls"
Return "application/vnd.ms-excel"
Case "xlsx"
Return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Case "pdf"
Return "application/pdf"
Case "doc"
Return "application/msword"
Case "docx"
Return "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Case "ppt"
Return "application/vnd.ms-powerpoint"
Case "pptx"
Return "application/vnd.openxmlformats-officedocument.presentationml.presentation"
Case Else
Return "application/octet-stream"
End Select
End Function
此时,使用此功能 xls/xlsx/pdf/.. 可以下载正确名称的文件,我想知道是否需要在此处或在 web.config 中指定所有 mime 类型以使下载工作。
有谁知道 chrome 发生了什么以及如何修复这个“错误”?
这是下载功能,应该没问题,因为它以前可以工作。
Public Shared Sub StreamFileToClient(ByVal memoryStream As IO.MemoryStream, ByVal fileName As String, ByVal fileType As String)
Try
memoryStream.Position = 0
'Serve to client
System.Web.HttpContext.Current.Response.ClearHeaders()
System.Web.HttpContext.Current.Response.ClearContent()
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;attachment; filename=" & fileName & "." & fileType)
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", memoryStream.Length.ToString())
System.Web.HttpContext.Current.Response.ContentType = GetContentType(fileType)
'octet-stream";
System.Web.HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray)
'System.Web.HttpContext.Current.Response.Flush()
'well good to use completerequest rather than .end nand .close. Read MSDN.
'System.Web.HttpContext.Current.Response.End()
'System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
Finally
System.Web.HttpContext.Current.Response.Flush()
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest()
memoryStream.Flush()
memoryStream.Dispose()
End Try
End Sub