Hi,
I'm trying to understand why this very simple HttpModule fails. The code is a precursor to a simple HttpUrlRewriter that I need to develop for a test project.
It appears that whenever I test the Request, and then execute a Response, the output is not written to the stream!
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?
Thanks for any help.
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
}