2011-01-28 49 views
2

我試圖編寫一個小型web應用程序,用於將請求轉發到我的頁面到我網站上的新頁面。首先IM實現的IHttpHandler和ProcessRequest方法我簡單想打印出來的頁面請求,我孔德是這樣的:我如何測試我的asp.net httphandler

public class RedirectHandler : IHttpHandler 
    { 
     public bool IsReusable 
     { 
      get { return true; } 
     } 

     public void ProcessRequest(HttpContext context) 
     { 
      context.Response.Write(context.Request.Path); 
     } 
    } 

我已經註冊在web.config中,有一個問題,測試處理器。我通過visual studio開始它,它只是列出我的文件。然後,我從瀏覽器請求一個文件,並期望在瀏覽器中看到該名稱,但拋出了該頁面未找到的異常。我已經刪除了所有其他的.aspx頁面,所以我唯一的「頁面」是我的http處理程序。任何人都可以將我指向正確的方向嗎?

編輯 配置設置(的web.config)

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    <handlers> 
     <add name="RedirectHandler" resourceType="Unspecified" verb="*" path="*.html" type="Jeeves.RedirectHandler"/> 
    </handlers> 
    </system.webServer> 
+0

發表您的配置設置 – NotMe 2011-01-28 20:31:50

+0

你是否看到任何錯誤被記錄到事件日誌或類似的東西?它甚至會達到你的斷點嗎? – 2011-01-28 20:35:55

回答

0

system.webServer /處理程序配置元素中的條目,如果你正在運行IIS 7(在集成模式是唯一有效的)。無論是在項目的屬性的網絡部分指定使用本地IIS Web服務器(如果你有IIS7)使用的System.Web/HttpHandlers的元素代替:

<system.web> 
    <httpHandlers> 
     <add verb="*" path="*.html" type="Jeeves.RedirectHandler"/> 
    </httpHandlers> 
</system.web>