我有一个不会触发的HTTP处理程序。我刚注意到在我的代码中添加了一个中断。
奇怪的是调用处理程序的页面和HTTPhandler具有相同的名称空间...... 我真的不明白为什么......
最近有人面对过这个吗? 提前谢谢
编辑:
我的ImageHandler.ashx.cs:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Actilog.Parametre.Famille
{
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ImageHandler : IHttpHandler
{
string strcon = ConfigurationManager.AppSettings["DB_CRACQConnectionString"].ToString();
public void ProcessRequest(HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(strcon);
connection.Open();
SqlCommand command = new SqlCommand("select Image from Table_test where ImageID=" + imageid, connection);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
connection.Close();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
我称之为的页面:
<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="False"
CssClass="Gridview" HeaderStyle-BackColor="#7779AF"
HeaderStyle-ForeColor="white">
<Columns>
<asp:BoundField DataField="ImageName" HeaderText="Image Name" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="150px"
ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID") %>' Width="150px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我的Web.config部分:
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
<!-- ******* Register the RadUploadProgressHandler for IIS prior to v.7 ****** -->
<add path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler"
verb="*" validate="false" />
</httpHandlers>
答案 0 :(得分:0)
在你的web.config中你应该添加:
<httpHandlers>
...
<add path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
verb="*" validate="false" />
...
</httpHandlers>
允许Asp.Net使用正确的IHttpHandler类管理包含“ImageHandler.ashx”的每个请求。并记得添加:
<system.webServer>
<handlers>
...
<add name="ImageHandler" path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler"
verb="*" validate="false" />
...
</handlers>
</system.webServer>
在您的生产环境中(如果您使用的是IIS7 +)。