ASP.NET捕获并替换Global.asax中的输出

ale*_*exn 2 c# asp.net global-asax

我需要替换从我网站上的每个页面发送的一些数据,我认为使用Global.asax进行处理.这是我到目前为止尝试过的:

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..");
}
Run Code Online (Sandbox Code Playgroud)

但这给了我一个ArgumentException.我究竟做错了什么?有没有更好的方法来做到这一点?

谢谢

M4N*_*M4N 8

有没有更好的方法来做到这一点?

一个HTTP模块可能是这样的任务是更好的选择.

有关如何修改请求响应的示例,请查看本文:使用响应过滤器生成符合XHTML的页面.