ASP.NETページでZipファイルを動的に生成してから、ストリームをResponseに送信しています。
Firefoxでは、という名前のファイルをダウンロードできますImages.zip
。正しく動作します。Internet Explorer 7では、と呼ばれるファイルをダウンロードしようとしますが、ZipExport.aspx
それが汎用ハンドラーにある場合ZipExport.ashx
は、サーバー上で見つからないと表示され、失敗します。
これが私のコードです:
Response.BufferOutput = true;
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment; filename=Images.zip");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
Response.Cache.SetMaxAge(System.TimeSpan.Zero);
ZipFile zip = new ZipFile();
zip.AddFile(Server.MapPath("sample1.png"));
zip.Save(Response.OutputStream);
特定のファイルのHTTPHandlerを作成して、IISに登録したくありません。
私が見逃している単純なものがありますか、それともInternet Explorerが私のcontent-dispositionヘッダーを無視したことに責任がありますか?
編集:私はこれらの行を削除し、物事はうまくいきました:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
編集:誰かが興味を持っている場合は、これが動作するコードです:
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.BufferOutput = false;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition",
"attachment; filename=ChartImages.zip");
context.Response.Cache.SetNoServerCaching();
context.Response.Cache.SetMaxAge(System.TimeSpan.Zero);
using(ZipFile zip = new ZipFile())
{
zip.AddFile(context.Server.MapPath("sample1.png"));
zip.Save(context.Response.OutputStream);
}
context.ApplicationInstance.CompleteRequest();
}