C# 问题与:“;将图片另存为";在IE中,用于通过图像处理程序从数据库检索的图像

C# 问题与:“;将图片另存为";在IE中,用于通过图像处理程序从数据库检索的图像,c#,asp.net,C#,Asp.net,我有一个包含aspImage控件的网页 当我通过图像处理程序从数据库检索图像时,我可以在aspImage控件中显示该图像!但是问题是,当我右键单击图像并单击“将图片另存为”时,我会收到以下错误消息:正在保存或检索的文件类型已被阻止! 我想知道这是IE问题还是我的代码有问题?!有人帮忙吗 以下是我的图像处理程序代码: <%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Confi

我有一个包含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;
        }
    }

}

使用制度;
使用系统配置;
使用System.Data.SqlClient;
使用System.Web;
公共类处理程序:IHttpHandler,System.Web.SessionState.IRequiresessionState
{
SqlConnection conn=新的SqlConnection(ConfigurationManager.ConnectionString[“DBConnectionString”].ConnectionString);
公共void ProcessRequest(HttpContext上下文)
{
字符串TableName=context.Session[“TableToQuery”].ToString();
string ID=context.Session[“ID”].ToString();
SqlCommand comm=新的SqlCommand(“从“+TableName+”中选择*,其中ID=“+ID,conn”);
conn.Open();
SqlDataReader dr=comm.ExecuteReader();
里德博士();
context.Response.BinaryWrite((字节[])dr[“Image”]);
康涅狄格州关闭();
}
公共布尔可重用
{
得到
{
返回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>

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

至少您应该在二进制编写之前添加类似的内容

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

您的图像处理程序可能发送了错误的标题,但是如果没有测试url或示例代码,就不可能找到问题。@AlfonsoML我添加了源代码!如果你能帮助我,我会很高兴的!