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);
}
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