问题:“;将图片保存为“;在IE中用于经由图像处理器从数据库检索的图像

本文关键字:图像 图像处理 处理器 数据库 检索 用于 IE 保存 问题 | 更新日期: 2024-09-25 23:06:31

我有一个包含aspImage控件的网页当我通过图像处理程序从数据库中检索图像时,我可以在aspImage控件中显示该图像!但是。问题是,当我右键单击图像并单击"将图片另存为"时,我会收到错误消息:正在保存或检索的文件类型已被阻止!我想知道这是IE问题还是我的代码有问题?!有什么帮助吗?!

这是我的图像处理程序代码:

    <%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;
public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
    public void ProcessRequest(HttpContext context)
    {
        string TableName=context.Session["TableToQuery"].ToString();
        string ID=context.Session["ID"].ToString();
        SqlCommand comm = new SqlCommand("SELECT * FROM "+ TableName +" WHERE ID=" + ID, conn);
        conn.Open();
        SqlDataReader dr = comm.ExecuteReader();
        dr.Read();
        context.Response.BinaryWrite((byte[])dr["Image"]);
        conn.Close();
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

这是我展示图像的数据列表:

<asp:DataList ID="DL" runat="server" Width="100%" Height="100%" RepeatColumns="1"
                            RepeatDirection="Vertical">
                            <ItemTemplate>
                                <table style="height: 100%; width: 100%">
                                    <tr style="width: 100%; height: 350px">
                                        <td valign="middle">
                                            <asp:Image ID="IMage" runat="server" ImageUrl='<%# "Handler.ashx?ID=" + Eval("ID") %>' />
                                        </td>
                                    </tr>
                                    <tr style="width: 100%; height: 250px">
                                        <td valign="top">
                                            <asp:TextBox ID="txtDecoded" runat="server" TextMode="MultiLine" Width="316px"
                                                Height="200px" Text='<%#Eval("DecodedString")%>'></asp:TextBox>
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </asp:DataList>

问题:“;将图片保存为“;在IE中用于经由图像处理器从数据库检索的图像

您没有发送任何声明内容MIME类型的标头,只是发送一个context.Response.BinaryWrite

至少你应该在BinaryWrite 之前添加这样的东西

context.Response.ContentType = "image/jpeg";