我试图理解为什么这种非常简单的HttpModule失败。 该守则是我需要为测试项目开发的简明的HttpUrlRe author的前奏。
看来,每当我测试请求,然后执行答复时,产出就没有写给溪流!
I ve attached the debugger (VS 2008) to the module, and all 3 Response.Write statements in the below get executed, but only the two outer ones actually product output on the page. Have I missed a key understanding or caveat?
感谢任何帮助。
Exeucting Environment: ASP.NET 3.5/WinXP/IIS 5月
using System; using System.Collections.Generic; using System.Web; using System.Text; using System.Web.UI;
public class Interceptor : IHttpModule
{
#region IHttpModule Members
public void Dispose() { }
public void Init(HttpApplication context)
{
context.EndRequest += new EventHandler(TestHandler);
}
private void TestHandler(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext ctx = app.Context;
if (1 == 1)
{
ctx.Response.Write("Hello, 2"); // Works, as expected
}
string test = ctx.Request.Url.ToString();
if (test.Contains("/images")) {
ctx.Response.Write("Hello, never written"); // This code executes when the test passes, but nothing is ever written...
}
ctx.Response.Write("Hello"); // Works
}
#endregion
}