我需要替换从我的网站上的每个页面发送的一些数据,并且我认为使用Global.asax来完成。这是我到目前为止所尝试的:ASP.NET捕获并替换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..");
}
但是这给了我一个ArgumentException。我究竟做错了什么?有没有更好的方法来做到这一点?
感谢
哪一行给出了ArgumentException?异常中是否有更详细的消息? – 2009-05-04 08:53:41
StreamReader构造函数抛出ArgumentException,说它无法读取流。我也试着在Application_BeginRequest事件中做这件事,并从Response.Filter中读取。 – alexn 2009-05-04 08:59:41