mysqlデータベースの画像から画像のサムネイルをレンダリングするashxハンドラーを作成しました。ファイル名がクエリ文字列を介して渡されると、コンテンツ処理ファイル名が設定されます(ユーザーが[名前を付けて保存...]をクリックすると、ファイル名が表示されます)。ユーザーが「名前を付けて保存...」を選択すると、画像が正しく表示され、ファイル名が表示されますが、ファイルタイプは不明としてリストされ、ダウンロードするファイルにはタイプがありません。
他に試すことがないため、コンテンツ処理でファイル名の末尾に「.jpg」を追加しようとしましたが、これにより、すべての画像がuntitled.bmpとしてダウンロードされました。
byte[] imageData = null;
Image outputImage = null;
if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["pictureid"]))
pictureId = SafeConvert.ToInt(HttpContext.Current.Request.QueryString["pictureid"].Trim());
if (pictureId > -1)
{
if (!String.IsNullOrEmpty(fileName))
HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=" + fileName + ";");
imageData = new OHTManager().GetOrnamentImage(pictureId);
context.Response.ContentType = "text/jpeg";
context.Response.BinaryWrite(imageData);
}
else
{
throw new Exception("No image could be produced;");
}