Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get at the bytes sent you can use the <code><a href="http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx" rel="noreferrer">HttpResponse.Filter</a></code> property. 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. </p> <p>You can create a new <code><a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx" rel="noreferrer">System.IO.Stream</a></code> that wraps the existing <code>HttpResponse.Filter</code> stream and counts the bytes passed in to the <code>Write</code> method before passing them on. For example:</p> <pre><code>public class ContentLengthModule : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += OnBeginRequest; context.EndRequest += OnEndRequest; } void OnBeginRequest(object sender, EventArgs e) { var application = (HttpApplication) sender; application.Response.Filter = new ContentLengthFilter(application.Response.Filter); } void OnEndRequest(object sender, EventArgs e) { var application = (HttpApplication) sender; var contentLengthFilter = (ContentLengthFilter) application.Response.Filter; var contentLength = contentLengthFilter.BytesWritten; } public void Dispose() { } } public class ContentLengthFilter : Stream { private readonly Stream _responseFilter; public int BytesWritten { get; set; } public ContentLengthFilter(Stream responseFilter) { _responseFilter = responseFilter; } public override void Flush() { _responseFilter.Flush(); } public override long Seek(long offset, SeekOrigin origin) { return _responseFilter.Seek(offset, origin); } public override void SetLength(long value) { _responseFilter.SetLength(value); } public override int Read(byte[] buffer, int offset, int count) { return _responseFilter.Read(buffer, offset, count); } public override void Write(byte[] buffer, int offset, int count) { BytesWritten += count; _responseFilter.Write(buffer, offset, count); } public override bool CanRead { get { return _responseFilter.CanRead; } } public override bool CanSeek { get { return _responseFilter.CanSeek; } } public override bool CanWrite { get { return _responseFilter.CanWrite; } } public override long Length { get { return _responseFilter.Length; } } public override long Position { get { return _responseFilter.Position; } set { _responseFilter.Position = value; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload