Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t通过图像处理程序在图像控件中检索图像_C#_Asp.net_Image_Handler - Fatal编程技术网

C# Can';t通过图像处理程序在图像控件中检索图像

C# Can';t通过图像处理程序在图像控件中检索图像,c#,asp.net,image,handler,C#,Asp.net,Image,Handler,我成功地将图像存储在数据库中,但我无法检索它 我有一个数据库ImageDatabase,有一个表Pict,其中包含两列Letter(varchar(50))(pk)和Picture(image) 我的Handler.ashxcode: using System; using System.Web; using System.Data.SqlClient; using System.IO; public class Handler : IHttpHandler { public void Pr

我成功地将图像存储在数据库中,但我无法检索它

我有一个数据库
ImageDatabase
,有一个表
Pict
,其中包含两列
Letter
varchar(50)
)(pk)和
Picture
image

我的
Handler.ashx
code:

using System;
using System.Web;
using System.Data.SqlClient;
using System.IO;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
    string L = (context.Request.QueryString["Letter"]);       
    SqlConnection connection = new SqlConnection();
    connection.ConnectionString = @"Data Source=RANJHANI-PC\SQLEXPRESS;Initial        Catalog=ImageDatabase;Integrated Security=True";
    string sql = "SELECT Picture FROM Pict WHERE Letter = @Ltr";
    SqlCommand cmd = new SqlCommand(sql, connection);
    cmd.Parameters.AddWithValue("@Ltr", L);
    connection.Open();
    byte[] bytes = (byte[]) cmd.ExecuteScalar();
    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(bytes);        
    connection.Close();
}   

public bool IsReusable {
    get {
        return false;
    }
}
}

我的默认值.aspx

<img id="img1" src="Handler.ashx?Letter='a'" />


请在这方面帮助我,如果我犯了错误,

请在写入二进制文件之前尝试清除响应流

context.Response.Clear();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(bytes);
context.Response.End();

当在浏览器中请求
Handler.ashx?Letter='a'
时,您会得到什么?无兄弟,我的图像未加载,图像控件上有一个红十字图标。请使用firebug或chrome developer工具检查结果,你是否得到了200 OK或500个内部错误,它说加载失败,给定URL仍然收到相同的问题在
context.Response.BinaryWrite(字节)上设置断点并检查字节长度