2012-03-13 129 views
0

我有一個不啓動的HTTP處理程序。我只注意到給我的代碼添加一箇中斷。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

你是如何從頁面調用處理程序的? – Ramesh 2012-03-13 14:52:24

+0

嘗試在問題中添加更多上下文,發佈代碼,web.config部分等,因爲它無法回答。 – Icarus 2012-03-13 14:53:05

+0

請顯示一些來源和配置... – Yahia 2012-03-13 14:53:30

回答

1

在你的web.config你應該增加:

<httpHandlers> 
    ... 
    <add path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler" 
     verb="*" validate="false" /> 
    ... 
</httpHandlers> 

爲了讓Asp.Net管理每個請求containig「ImageHandler.ashx」用正確的IHttpHandler類。並記住添加:

<system.webServer> 
    <handlers> 
    ... 
    <add name="ImageHandler" path="ImageHandler.ashx" type="Actilog.Parametre.Famille.ImageHandler" 
      verb="*" validate="false" /> 
    ... 
    </handlers> 
</system.webServer> 

在您的生產環境(如果您使用IIS7 +)。

+0

謝謝,但我剛剛添加兩者都不起作用! argh – Slrg 2012-03-13 15:13:47

+0

您是否試圖在處理程序的ProcessRequest中放置斷點?第一步是瞭解處理程序是否觸發。 – tanathos 2012-03-13 15:16:12

+0

是的,我嘗試過,視覺工作室並沒有停止...所以處理程序沒有解僱 – Slrg 2012-03-13 15:18:40

相關問題