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

标签 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..");
}

但这给了我一个 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/

相关文章:

javascript - 为什么成功 : function() doesn't work

.net - 如何在 ASP.NET MVC 中记录未处理的异常?

ASP.NET Session_End 事件未触发

c# - dotnet 核心方法 'ValidateOptions' ... 没有实现

c# - 不明白<>0是什么意思

c# - 将 MVC 应用程序作为子应用程序运行?

c# - Global.asax 不工作

c# - 使用 C# 和 tableadapter 循环结果

c# - Dns.GetHostAddress(主机名)在 Ubuntu 16.04 中没有这样的设备或地址异常

c# - 构建表示 Rubric 的对象的正确方法是什么