我试图下载通过HTTPS &它无法在IE浏览器,但火狐& Chrome浏览器的完美文件:文件下载失败通过HTTPS在IE
ASPX代码如下:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CRISIIWebApplication1.Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
后面的按钮点击代码代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string filename = TextBox1.Text;
string filepath = Server.MapPath(filename);
byte[] bytFile = null;
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(filepath).Length;
bytFile = br.ReadBytes((int)numBytes);
string extension = ".xlsx";
Response.ClearHeaders();
Response.Clear();
Response.Buffer = true;
if (extension == ".doc")
{
Response.ContentType = "application/vnd.ms-word";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
}
else if (extension == ".docx")
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
}
else if (extension == ".xls" || extension == ".xlsx")
{
if (extension == ".xls")
{
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
}
else
{
Response.ContentType = "application/ms-excel";
//Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
}
}
else if (extension == ".pdf")
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
}
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytFile);
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
}
请帮
您是否收到错误或请求是否消失?任何有关您正在经历的其他信息都会有所帮助。 – 2011-03-04 19:53:10
你是什么意思,它失败了?你会得到什么样的错误? – 2011-03-04 19:53:28
它如何失败? – 2011-03-04 19:53:59