我試圖下載通過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