gpt4 book ai didi

asp.net - SSL 期间 IE9 中的下载文件行为更改

转载 作者:行者123 更新时间:2023-12-04 06:31:05 25 4
gpt4 key购买 nike

我目前有一个 .NET http 处理程序,用于处理将文件传递到 Web 浏览器进行下载。 IE6+、FireFox、Chrome 和 Safari 都可以使用此代码,但新的 IE9 无法下载,但仅在 SSL 中时。

当我点击链接下载文件时:https://rootwebsite/taskmanager/DownloadFiles.ashx?fileId=3b2c7e41-f51a-445d-9627-f4f4481e1425
IE9 打开保存对话框并显示给我 DownloadFiles_ashx?fileId=3b2c7e41-f51a-445d-9627-f4f4481e1425作为文件名,但拒绝下载文件。

如果我将链接更改为 http://然后代码工作正常,文件下载。

有什么不同?我错过了什么?

这是我的代码:

public void WriteByteArrayToHttp(HttpResponse response, string fileName, string contentType, Stream file, bool downloadFile)
{
using (file)
{
if (downloadFile)
{
response.Clear();
response.ClearHeaders();
response.ClearContent();
response.AddHeader("Content-Disposition",
string.Format("attachment; filename={0}", HttpUtility.UrlEncode(fileName)));
}
response.AddHeader("Content-Length", file.Length.ToString());

// Added with suggestion of YSlow FireFox plug-in
// Specifies how long the file is valid for in cache in seconds
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// See 14.9 Cache-Control
// 6 Hours
response.AddHeader("max-age", "21600");
response.ContentType = contentType;

// At the time of this writing, we are running IIS6, BUT if we decide to go to IIS7
// there is a 28.6MB limit to content size both up and down by default
// See http://msdn.microsoft.com/en-us/library/ms689462.aspx
// This would be a problem for a number of files we serv up with the Original method
// so this chunking method replaces that.
// See http://support.microsoft.com/kb/812406 as the base for this change.
// Tested with file between 1MB and 3GB

// Total bytes to read:
long dataToRead = file.Length;

// Buffer to read 10K bytes in chunk:
byte[] buffer = new Byte[10000];

try
{
while (dataToRead > 0)
{
// Verify that the client is connected.
if (response.IsClientConnected)
{
// Read the data in buffer.
// Length of the file:
int length = file.Read(buffer, 0, 10000);

// Write the data to the current output stream.
response.OutputStream.Write(buffer, 0, length);

// Flush the data to the HTML output.
response.Flush();

buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
}
catch (HttpException hex)
{
if (!hex.Message.StartsWith("The remote host closed the connection"))
{
throw;
}
}
}
}

web.config 将处理程序定义为:
 <system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="DownloadFiles.ashx" path="DownloadFiles.ashx" verb="*" type="Russound.Web.HttpHandlers.DownloadFileHandler" resourceType="Unspecified" preCondition="integratedMode"/>
</handlers>
</system.webServer>
</configuration>

最佳答案

可能与

  • 一些 cache control headers (或 this one ;另见此 question )或
  • 一个 Internet Explorer 选项,可防止 SSL 加密的页面被缓存/存储在磁盘上,或
  • 他们俩...

  • 昨天让我头疼(这是我的第二个)。

    如果你问我,这个 Internet Explorer 选项 Do not save encrypted pages to disk应该只适用于缓存而不是故意下载......但是,嘿,这是我们正在谈论的微软,所以无论如何它不需要任何意义。

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

    Update Feb. 2011: I've modified the file download logic for IE9. IE9 should be able to successfully download a file regardless of HTTPS or Cache-Control headers unless you have the "Do not save encrypted pages to disk" option set.

    关于asp.net - SSL 期间 IE9 中的下载文件行为更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5407038/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com