这是一个asp.net 3.5网站。
文件可以下载正确的IE / FF。 但不是铬。
该文件被下载的“ASPS_Page_Name.aspx”。
然而,我的工作我的Chrome浏览器更新到20.0.1132.47米前。
我有这个功能来过滤掉MIME类型(用于FF,以前的镀铬不需要此功能)
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类型进行下载工作。
没有人知道发生了什么事铬,以及如何解决这个“错误”?
这是下载功能,应该确定CAZ它的工作原理之前。
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