我需要替换从我网站上每个页面发送的一些数据,我想用 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。我究竟做错了什么?有没有更好的方法来做到这一点?
谢谢
最佳答案
Is there any better way to do this?
A HttpModule可能是完成此类任务的更好选择。
有关如何修改请求响应的示例,请查看这篇文章:Producing XHTML-Compliant Pages With Response Filters .
关于c# - ASP.NET 捕获并替换 Global.asax 中的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/819326/