views:

314

answers:

1

Hi!

I need to replace some data that's sent from every page on my site, and I think doing it with Global.asax. This is what I have tried with so far:

void Application_PreSendRequestContent(object sender, EventArgs e)
{
    System.IO.StreamReader sr = new System.IO.StreamReader(Response.OutputStream);
    String output = sr.ReadToEnd();

    Response.ClearContent();
    Response.Write("Testing..");
}

But this gives me an ArgumentException. What am I doing wrong? Is there any better way to do this?

Thanks

+4  A: 

Is there any better way to do this?

A HttpModule might be the better choice for such a task.

For an example how to modify the response of a request, have a look at this article: Producing XHTML-Compliant Pages With Response Filters

M4N
Thanks for your answer, i'm going to look in to that.
alexn