ASP.NET サーバーでファイルを提供する際に奇妙な問題が発生しています。
ユーザーがリンクをクリックすると、ファイルのダウンロード ダイアログが表示されます。WMV を WMP で開くことも、PDF を Adobe で開くこともできません。
これを強制するには、WMV、PDF などにジャンプする次の HTTP ハンドラーを使用します。
public void ProcessRequest(HttpContext context)
{
// don't allow caching
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
context.Response.Cache.SetExpires(DateTime.MinValue);
string contentDisposition = string.Format("attachment; filename=\"{0}\"", Path.GetFileName(context.Request.PhysicalPath));
string contentLength;
using (FileStream fileStream = File.OpenRead(context.Request.PhysicalPath))
{
contentLength = fileStream.Length.ToString(CultureInfo.InvariantCulture);
}
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", contentDisposition);
context.Response.AddHeader("Content-Length", contentLength);
context.Response.AddHeader("Content-Description", "File Transfer");
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.TransmitFile(context.Request.PhysicalPath);
}
フィドラーでスニッフィングすると、これらは実際に送信されたヘッダーです。
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 8661299
Content-Type: application/octet-stream
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment; filename="foo.wmv"
Content-Description: File Transfer
Content-Transfer-Encoding: binary
X-Powered-By: ASP.NET
Date: Wed, 04 Apr 2012 09:38:14 GMT
ただし、Adobe Reader の場合と同じように、WMV リンクをクリックすると WMP が開きます。IE ウィンドウ内で Adobe Reader が開きます。
この問題は Firefox では発生していないようですが、Windows 7 (32 ビット) 上の IE8 (32 ビット) で発生します。
何か助けはありますか?