文件下载失败过在IE HTTPS

编程入门 行业动态 更新时间:2024-10-28 21:20:25
本文介绍了文件下载失败过在IE HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想下载一个文件通过HTTPS和放大器;它不能在IE,但与Firefox和功放完美的作品;铬:

I'm trying to download a file over HTTPS & it fails in IE but works perfectly with Firefox & Chrome:

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>

代码背后的按钮,点击代码如下:

Code behind code on button click is as follows:

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(); }

请帮忙

推荐答案

由于用户 SquidScareMe 写道,你要忽略/不碰下载他们通过SSL当Office文件高速缓存设置。

As user SquidScareMe writes, you have to ignore/don't touch the cache settings for Office files when downloading them over SSL.

我有像片段的 ashx的处理程序

// "Internet Explorer is unable to open Office documents from an SSL Web site". // support.microsoft/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"; }

更多推荐

文件下载失败过在IE HTTPS

本文发布于:2023-11-26 15:44:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634303.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   HTTPS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!