2011-03-04 70 views
0

我試圖下載通過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(); 
    } 

請幫

+0

您是否收到錯誤或請求是否消失?任何有關您正在經歷的其他信息都會有所幫助。 – 2011-03-04 19:53:10

+0

你是什麼意思,它失敗了?你會得到什麼樣的錯誤? – 2011-03-04 19:53:28

+0

它如何失敗? – 2011-03-04 19:53:59

回答

4

隨着用戶SquidScareMe寫道,你必須忽略/不碰緩存設置用於通過SSL下載Office文件。

我有一個.ashx處理器擁有像一個片段:

// "Internet Explorer is unable to open Office documents from an SSL Web site". 
// http://support.microsoft.com/kb/316431/en-us 
if (!context.Request.IsSecureConnection || !isInternetExplorer(context)) 
{ 
    // No cache. 
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    context.Response.AppendHeader(@"Pragma", @"no-cache"); 
} 

有了這個功能:

private static bool isInternetExplorer(HttpContext context) 
{ 
    return context.Request.Browser.Browser == @"IE"; 
} 
+1

我發現如果你像這樣''Response.AddHeader(「Cache-Control」,「no-store,no-cache」)手動設置頭部,'它會工作並使用你的緩存頭部。請參閱:http://blogs.msdn.com/b/ieinternals/archive/2009/10/03/internet-explorer-cannot-download-over-https-when-no-cache.aspx。 – 2012-08-30 16:56:21

1

http://blogs.msdn.com/b/ieinternals/archive/2009/10/03/internet-explorer-cannot-download-over-https-when-no-cache.aspx

更新:Ahah! http://www.openrdf.org/issues/browse/SES-63

SOLUTION: 互聯網Explorer的>工具菜單 - > Internet選項 - >高級選項卡 轉至安全部分的底部一路。 清除了「不將加密的頁面到磁盤」 關閉所有Internet Explorer窗口 啓動IE檢查並下載文件再次

+2

在我看來,這不是一個解決方案,因爲用戶必須做一些客戶端調整。更好的辦法是不要通過SSL緩存Office文件。 – 2011-03-04 20:11:25

1

它的解決方案針對此問題是在ISA激活壓縮。經過這一步後,網站可以傳輸文件沒有任何問題! 當您嘗試在使用無緩存時通過HTTPS傳輸文件時,會出現此問題。