ASP.NET捕获并替换Global.asax中的输出 [英] ASP.NET Capture and replace output in Global.asax
本文介绍了ASP.NET捕获并替换Global.asax中的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要替换从网站上每个页面发送的一些数据,我认为可以使用Global.asax来完成.到目前为止,这是我尝试过的:
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..");
}
但这给了我一个ArgumentException.我究竟做错了什么?有什么更好的方法吗?
But this gives me an ArgumentException. What am I doing wrong? Is there any better way to do this?
谢谢
推荐答案
还有更好的方法吗?
Is there any better way to do this?
对于这样的任务, HttpModule 可能是更好的选择
A HttpModule might be the better choice for such a task.
For an example on how to modify the response of a request, have a look at this article: Producing XHTML-Compliant Pages With Response Filters.
这篇关于ASP.NET捕获并替换Global.asax中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文