How to use PreSendRequestContent
I have bben trying to alter the output of a page using PreSendRequestContent. The event get raised but the contents of the document do not change. Here is an example from ASP.NET Professional 2.0 Special Edition.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace Demo
{
public class AppendMessage : IHttpModule
{
private HttpContext _current = null;
#region IHttpModule Members
public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
}
public void Init(System.Web.HttpApplication context)
{
_current = context.Context;
context.PreSendRequestContent +=
new EventHandler(context_PreSendRequestContent);
}
void context_PreSendRequestContent(object sender, EventArgs e)
{
//alter the outgoing content by adding a HTML comment.
string message = "<!-- This page has been post processed at " +
System.DateTime.Now.ToString() +
" by a custom HttpModule.-->";
_current.Response.Output.Write(message);
}
#endregion
}
}
I looked on the internet and find examples which have similiar code. Can anyone suggest why does not get appended to the contents of the document.
Thanks.
|