PostRequestHandlerExecute 中的响应长度
我想知道出于记录目的,事后发送给用户的响应到底有多长。有什么方法可以从 asp.net 中的 HttpModule 执行此操作(在 PostRequestHandlerExecute 事件中)。
I want to find out exactly how long the Response sent to the user was, after the fact, for logging purposes. Is there any way to do this from an HttpModule in asp.net (in the PostRequestHandlerExecute event).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,
HttpResponse.OutputStream
是只写,因此这不是很简单 - 任何尝试查看输出流的Length
属性会抛出异常。我见过的唯一解决方案是对 Response 对象应用过滤器,以便过滤器可以计算字节数。
快速 Google 搜索找到了我这里,这似乎接近实现我记得。
Unfortunately,
HttpResponse.OutputStream
is write-only, so this is not very straightforward - any attempts to look at theLength
property of the output stream will throw an exception.The only solution to this I've ever seen is by applying a filter to the
Response
object, so that the filter can count the bytes.A quick Google search landed me here, which seems close to the implementation I remember.
希望它有帮助
MyRewriterStream 类
Wish it Help
MyRewriterStream Class