送信ファイルHttpContext原因のブラウザを
-
23-08-2019 - |
質問
を送りたいと思いファイルをユーザーを用いHttpHandler.すべてのブラウザで後に閲覧-ダウンロード"でダウンロードファイルを少なくとも一度は、ブラウザの申請その後の景色/ダウンロードを掲げています。こちらのコード:
private void TransmitFile(HttpContext context, string filePath, string downloadName, bool forceDownload)
{
if (File.Exists(filePath))
{
string fileName = System.IO.Path.GetFileName(filePath);
string extension = Path.GetExtension(filePath);
FileInfo fileInfo = new FileInfo(filePath);
// set the response info/headers
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
if (forceDownload)
{
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + downloadName.Replace(" ", "_") + extension);
context.Response.BufferOutput = false;
}
string type = "";
// set known types based on file extension
if (extension != null)
{
switch (extension.ToLower())
{
case ".tif":
case ".tiff":
type = "image/tiff";
break;
case ".jpg":
case ".jpeg":
type = "image/jpeg";
break;
case ".gif":
type = "image/gif";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case "pdf":
type = "Application/pdf";
break;
case "png":
type = "image/png";
break;
case "bmp":
type = "image/bmp";
break;
default:
type = "application/octet-stream";
break;
}
}
context.Response.ContentType = type;
context.Response.TransmitFile(filePath);
context.Response.Flush();
}
else
{
Immersive.Diagnostics.Log.Warn("Requested file does not exist: " + filePath, this);
Immersive.Diagnostics.Log.Warn("", this);
}
}
している呼び出しに応じます。あります。End()がょうか?たも離、除去が続いています。
編集:
こTransmitFileが古くから知られている。徹底的な説明ができるものと期待されますhttp://www.improve.dk/blog/2008/03/29/response-transmitfile-close-will-kill-your-application
取り出して、そのTransmitFile変WriteFileより行っており、現在のコンビニエンスストアでのお支.
context.Response.WriteFile(filePath);
context.Response.Flush();
context.Response.Close();
解決
この場合の既知の問題の場合はサーバーだからダウンロード走Windows Server2003SP1.
こちらはhotfix: http://support.microsoft.com/kb/902780
また、チェックす OutputCache
のページでは、その場合、ダウンロードで再度はどのくらい実装されているか。
他のヒント
その理由のない方のバッファリング?まFlush()グでもない使用しています。とあると思いまいに応じます。End()の後にフラッシュ().
いことかき試験によって自作してました。
所属していません StackOverflow