我有一個IHttpHandler,我相信可以從重用中受益,因爲它設置昂貴,並且是線程安全的。但是每個請求都會創建一個新的處理程序。我的處理程序沒有被重用。IHttpHandler IsReusable,但沒有得到重用
以下是我的簡單測試用例,沒有昂貴的設置。這個簡單的例子演示了我的問題:
public class MyRequestHandler : IHttpHandler
{
int nRequestsProcessed = 0;
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
nRequestsProcessed += 1;
Debug.WriteLine("Requests processed by this handler: " + nRequestsProcessed);
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
}
Requests processed by this handler: 1
Requests processed by this handler: 1
Requests processed by this handler: 1
Requests processed by this handler: 1... at least 100 times. I never see > 1.
我誤解了IsReusable的工作原理嗎?還有什麼可以打敗重用嗎?我的處理程序正在從Silverlight應用程序調用,如果這有所幫助。
你是如何處理程序安裝到您的應用程序?通過web.config或編程? – Jacob
這是我第一個這樣的應用程序。我在Visual Studio中創建了一個新的ASP.NET Web站點項目。爲了運行服務器,我正在運行Visual Studio中的Debug。 –
我在問你如何配置'MyRequestHandler'運行。例如,它是在你的web.config中配置的,還是你有'Global.asax'中的代碼來註冊它? – Jacob