データベースからイメージに読み込まれた.aspxページを持つアプリケーションをメンテナンスし、Response.BinaryWrite()を使用してクライアントに書き戻します。これはずっと前に完全に機能しました。 2つの点が変更され、アプリケーションを.NET 3.5にアップグレードし、職場のすべてのコンピュータをIE7にアップグレードしました。.aspxページIE7のResponse.BinaryWriteイメージ
Firefox上ですべてうまく動作しますが、IE7には赤いXが表示されます。この問題はIE7に関連していると思いますか? .aspxフォームから画像を読み込まないようにするセキュリティ設定がありますか?拡張子ではなく内容の種類に基づいて表示するように設定されています。
ここにいくつかのコードを示します。私が言ったように、私はちょうどこのアプリを維持し、それを書きませんでした。私はセッションを使用してそれを行うのは素晴らしい方法ではないが知っているが、それは私が持っているとスイッチのステートメントは単なる "重量ですか?
<asp:image id="imgContent" runat="server" Visible="true" ImageUrl="ProductContentFormImage.aspx"></asp:image>
protected void Page_Load(object sender, System.EventArgs e)
{
Hashtable hshContentBinary = (Hashtable)Session["hshContentBinary"];
byte[] content = (byte[]) hshContentBinary["content"];
string extension = (string) hshContentBinary["extension"];
string contentTypePrefix = "application";
switch(extension.ToLower())
{
case "gif":
case "jpg":
case "bmp":
contentTypePrefix = "image";
break;
case "tif":
contentTypePrefix = "image";
break;
case "tiff":
contentTypePrefix = "image";
break;
case "eps":
contentTypePrefix = "image";
break;
default:
Response.AppendHeader(
"Content-disposition",
"attachment; filename=content." + extension);
break;
}
Response.ContentType = contentTypePrefix + "/" + extension;
Response.BinaryWrite(content);
}
EDIT:
OK、私はあなたの提案に続き、もう少し研究を通じて、私は次のようにメソッドを変更しているが、それはまだ動作しません。
protected void Page_Load(object sender, System.EventArgs e)
{
Hashtable hshContentBinary = (Hashtable)Session["hshContentBinary"];
byte[] content = (byte[]) hshContentBinary["content"];
string extension = (string) hshContentBinary["extension"];
string contentType;
string contentDisposition = "inline; filename=content." + extension;
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
switch(extension.ToLower())
{
case "gif":
contentType = "image/gif";
break;
case "jpg":
case "jpe":
case "jpeg":
contentType = "image/jpeg";
break;
case "bmp":
contentType = "image/bmp";
break;
case "tif":
case "tiff":
contentType = "image/tiff";
break;
case "eps":
contentType = "application/postscript";
break;
default:
contentDisposition = "attachment; filename=content." + extension;
contentType = "application/" + extension.ToLower();
break;
}
Response.Buffer = true;
Response.Expires = 0;
Response.ContentType = contentType;
Response.AddHeader("Content-Length", content.Length.ToString());
Response.AddHeader("Content-disposition", contentDisposition);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(content);
Response.End();
}