通过HTTP模块确定页面大小 [英] Determine size of page via HttpModule

查看:195
本文介绍了通过HTTP模块确定页面大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个容易为你:

我目前正在通过一个HttpModule记录的请求时间,我想找出个字节每个页面以及数量。

I'm currently logging request duration via an HttpModule and I'd like to find out the number of bytes each page is as well.

HttpContext.Current.Response.OutputStream.Length 抛出一个引发NotSupportedException

什么是简单的方法来做到这一点?

What's an easy way to do this?

推荐答案

我有一个实现流重写一个HttpModule。它从Stream类派生。在我的HttpModule,我有以下code:

I have an HttpModule that implements a stream rewriter. It derives from the Stream class. In my HttpModule I have the following code:

void app_PreRequestHandlerExecute(object sender, EventArgs e)
{
    HttpResponse response = HttpContext.Current.Response;
    response.Filter = new MyRewriterStream(response.Filter);
}

在流类我有以下的code覆盖缺省Write方法:

In the stream class I have the following code that overrides the default Write method:

public override void Write(byte[] buffer, int offset, int count)
{
     string outStr;
     outStr = UTF8Encoding.UTF8.GetString(buffer, offset, count);
     //Do useful stuff and write back to the stream
}

您可以只取字符串的长度在第二点

You can just take the length of the string at the second point

这篇关于通过HTTP模块确定页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆