aspx中放置了一个<asp:ImageButton ID="BtnDownload" runat="server" ImageUrl="~/Images/Download.gif" BorderColor="Blue" BorderStyle="Solid"  />其后台代码为:
Protected Sub BtnDownload_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnDownload.Click
     Response.Redirect("~/Download.aspx?fiName=" & System.Web.HttpUtility.UrlEncode("~/Software/Sports/体育图片.rar"))
End Sub而Download.aspx的后台代码为:
Imports System.IO
Partial Class Download
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim path As String = Server.MapPath(Request.Params("fiName"))
        Dim file As New FileInfo(path)
        Response.Clear()        Response.Charset = "UTF-8"
        Response.ContentEncoding = System.Text.Encoding.UTF8
        Response.AddHeader("Content-Disposition", "attachment;filename=" & HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8))        Response.AddHeader("Content-Length", file.Length.ToString)
        Response.ContentType = "application/octet-stream"        Response.WriteFile(file.FullName)
        Response.End()
    End Sub
End Class点击BtnDownload,弹出保存文件对话框,在IE中文件名正常,而在FoxFire中却再现乱码,不知该如何解决?

解决方案 »

  1.   

    在FireFox下中文文件名要用Quoted-Printable编码:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim path As String = Server.MapPath(Request.Params("fiName"))
    Dim file As New FileInfo(path)
    Response.Clear() Dim filename As String
    If Request.UserAgent.Contains("MSIE") Then
    filename = HttpUtility.UrlEncode(file.Name, Encoding.UTF8)
    Else
    filename = Convert.ToBase64String(Encoding.UTF8.GetBytes(file.Name))
    filename = "=?UTF-8?B?" & filename & "?="
    End If Response.Charset = "UTF-8"
    Response.ContentEncoding = System.Text.Encoding.UTF8
    Response.AddHeader("Content-Disposition", "attachment;filename=" & filename) Response.AddHeader("Content-Length", file.Length.ToString)
    Response.ContentType = "application/octet-stream" Response.WriteFile(file.FullName)
    Response.End()
    End Sub