文件下载失败过在IE HTTPS [英] File download fails over https in IE

查看:127
本文介绍了文件下载失败过在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".
// 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";
}

这篇关于文件下载失败过在IE HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆