Загрузите изменения поведения файла в IE9 во время SSL - PullRequest
2 голосов
/ 23 марта 2011

В настоящее время у меня есть обработчик .NET http, который обрабатывает передачу файлов в веб-браузеры для загрузки. 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>

1 Ответ

3 голосов
/ 13 апреля 2011

Может иметь отношение к

Дала мне головную больвчера (это был второй для меня).

Если вы спросите меня, эта опция Internet Explorer Do not save encrypted pages to disk должна применяться только к кешированию, но не к преднамеренным загрузкам ... но хорошо, эй, это Microsoftмы говорим о том, что в любом случае это не должно иметь никакого смысла.

См. здесь: http://blogs.msdn.com/b/ieinternals/archive/2009/10/03/internet-explorer-cannot-download-over-https-when-no-cache.aspx:

Обновление февраль 2011: Я изменил логику загрузки файлов для IE9.IE9 должен иметь возможность успешно загружать файл независимо от заголовков HTTPS или Cache-Control, если у вас не установлен параметр «Не сохранять зашифрованные страницы на диск».

...