2
我試圖使用HTTP哈德勒,所以我創建了一個類lirary項目,並添加以下代碼:爲什麼我的HttpHandler不被解僱?
namespace MyProject.Handlers
{
public class Class1 : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Hello from custom handler.");
}
}
}
然後我編譯它,它產生的MyProject.Handlers.dll文件。我把它放在我的asp.net bin文件夾,並已將此添加到asp.net
<system.webServer>
<handlers>
<add name="TutorialHandler" verb="*" path="*" type="MyProject.Handlers.Class1, MyProject.Handlers" modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="File" />
</handlers>
<modules runAllManagedModulesForAllRequests="true">
//some stuff I *think* it doesn't make a difference
</modules>
//some stuff I *think* it doesn't make a difference
</system.webServer>
和
<system.web>
<httpHandlers>
<add verb="*" path="*" type="MyProject.Handlers.Class1, MyProject.Handlers" />
</httpHandlers>
</system.web>
,但它只是不會被調用! 我開始調試器,設置斷點,但它不停止。如果我在firebug中檢查輸出html,則「來自自定義處理程序的Hello」這個句子不存在。
我在做什麼錯?
感謝, 奧斯卡
編輯:我使用框架4.0,IIS7。 難道是我使用路線嗎? (不是直接調用index.aspx,而是/ home或類似的東西?)
一切看起來正確...你是否正在從正確的路徑加載頁面? – ic3b3rg
嘗試將路徑更改爲「handler.ashx」並加載該特定頁面 – ic3b3rg
您使用的是什麼版本的.NET框架? – nerdybeardo