I have an ISAPI filter for IIS 6 which does some custom processing using the bytes-sent field of the response. I’d like to update that for IIS 7, but I’m running into a problem. None of the IIS 7 events seem to have access to the content-length, bytes sent, or any data which would let me calculate the content-length or bytes sent. (I know the content-length header and bytes sent are not the same, but either will work for this purpose.)
From what I can tell, the content-length header is added by HTTP.SYS after the managed modules have finished executing. Right now I have an event handler which runs on EndRequest. If I could get at the output stream I could calculate what I need myself but the managed pipeline doesn’t seem to have access to that either.
Is there some way of getting the content-length or bytes sent in the managed pipeline? Failing that, is there some way I can calculate content-length or bytes sent from objects available in the managed pipeline?
To get at the bytes sent you can use the
HttpResponse.Filterproperty. As the MSDN docs say this property gets or sets a wrapping filter object that is used to modify the HTTP entity body before transmission.You can create a new
System.IO.Streamthat wraps the existingHttpResponse.Filterstream and counts the bytes passed in to theWritemethod before passing them on. For example: