Tag: transmitfile

文件名和哑剧问题 – ASP.NET下载文件(C#)

我在ASP.NET应用程序中遇到了一个非常奇怪的问题。 当用户单击下载文件的按钮时,Internet Explorer / Chrome / Firefox会显示保存对话框,但文件名是ASPX页面的名称 (例如,如果页面名为Download.aspx,则下载对话框显示“文件”Download.zip)。 有时,在使用MIME类型时,下载对话框显示“Download.aspx”。 似乎您正在尝试下载该页面,但实际上是正确的文件。 ZIP扩展会发生这种情况,这是我的代码(我认为非常标准): this.Response.Clear(); this.Response.ClearHeaders(); this.Response.ClearContent(); this.Response.AddHeader(“Content–Disposition”, “attachment; filename=” + file.Name); this.Response.AddHeader(“Content-Length”, file.Length.ToString()); this.Response.ContentType = GETCONTENTYPE(System.IO.Path.GetExtension(file.Name)); this.Response.TransmitFile(file.FullName); this.Response.End(); GetContentType函数只返回文件的MIME。 我尝试使用application / x-zip-compressed , multipart / x-zip ,当然还有application / zip 。 使用application / zip Internet Explorer 8显示XML错误。 任何帮助都非常感激。 问候,