Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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# httphandler永远不会被命中_C#_Asp.net_.net_Httphandler - Fatal编程技术网

C# httphandler永远不会被命中

C# httphandler永远不会被命中,c#,asp.net,.net,httphandler,C#,Asp.net,.net,Httphandler,我正在使用HttpHandler从数据库中检索图像,然后在我的网页(aspx)上的图像web控件中将该处理程序用作ImageUrl。代码如下所示。但它不起作用,到目前为止我还不知道为什么。问题是HttpHandler从未被命中,如果我将断点保留在processrequest()上,它将永远不会被命中 下面是处理程序中的简单代码 public class ImageHandler : IHttpHandler { StaffMemberRepository db = new StaffMe

我正在使用HttpHandler从数据库中检索图像,然后在我的网页(aspx)上的图像web控件中将该处理程序用作ImageUrl。代码如下所示。但它不起作用,到目前为止我还不知道为什么。问题是HttpHandler从未被命中,如果我将断点保留在processrequest()上,它将永远不会被命中

下面是处理程序中的简单代码

public class ImageHandler : IHttpHandler
{
    StaffMemberRepository db = new StaffMemberRepository();
    public void ProcessRequest(HttpContext context)
    {
        int id = Convert.ToInt32(context.Request.QueryString["id"].ToString());
        byte[] image = db.GetImage(id);
        context.Response.ContentType = "image/jpg";
        context.Response.BinaryWrite(image);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
下面是我网页中的标记

asp:Image ID="imgStaff" runat="server" ImageAlign="Middle" ImageUrl="~/Handlers/ImageHandler.ashx?id=2"

有人能告诉我我做错了什么吗?

好吧,我现在明白我的愚蠢了。我刚刚在web.config中注册了我的处理程序,现在一切都正常了。

您能提供注册处理程序的web配置部分吗?您是否已将浏览器指向:Handlers/ImageHandler.ashx?id=2?我还没有在web.config中添加任何内容。我的想法可能很愚蠢,但我认为只要我在本地机器上使用ASP DEV server,我就可以跳过web.config部分。如果不是这样,请纠正我。@Jack-在我粘贴的标记代码中,您可以看到Imageurl指向~/Handlers/ImageHandler.ashx?id=2。