How to Get Size of HTTP Response Going Back To Client

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a HTTPModule and all I want to do is trace the size of the page
the client is requesting and that the web server is going to return. I
tried the following code but it throws an exception saying it is
unsupported..... Any help would be greatly appreciated....thanks.

void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication myHttpApplication =
(HttpApplication)sender;
Stream baseStream = myHttpApplication.Response.Filter;

orginalSize = baseStream.Length; //exception here!
{


and this.... both fail

void context_EndRequest(object sender, EventArgs e)
{
HttpApplication myHttpApplication = (HttpApplication)sender;
long orginalSize = 0;
long compressedSize = 0;

orginalSize =
myHttpApplication.Context.Response.OutputStream.Length; //fails

}
 
Mark,

This is something I would think you would have to do on the ISAPI level.
Basically, you can't know the length of the stream since it is being passed
through to the client. Streams like this have no clue what their length is.

You could write an ISAPI filter, and on responses and requests, you
could count the bytes that get sent to/from the server for each
request/response.

Hope this helps.
 
So there is no way to do this in C#??? Thanks.

Nicholas Paldino said:
Mark,

This is something I would think you would have to do on the ISAPI level.
Basically, you can't know the length of the stream since it is being passed
through to the client. Streams like this have no clue what their length is.

You could write an ISAPI filter, and on responses and requests, you
could count the bytes that get sent to/from the server for each
request/response.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark Overstreet said:
I am writing a HTTPModule and all I want to do is trace the size of the
page
the client is requesting and that the web server is going to return. I
tried the following code but it throws an exception saying it is
unsupported..... Any help would be greatly appreciated....thanks.

void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication myHttpApplication =
(HttpApplication)sender;
Stream baseStream = myHttpApplication.Response.Filter;

orginalSize = baseStream.Length; //exception here!
{


and this.... both fail

void context_EndRequest(object sender, EventArgs e)
{
HttpApplication myHttpApplication = (HttpApplication)sender;
long orginalSize = 0;
long compressedSize = 0;

orginalSize =
myHttpApplication.Context.Response.OutputStream.Length; //fails

}
 
Mark said:
So there is no way to do this in C#??? Thanks.

Hm... why not use HttpRsponse.Filter to count all bytes written to the
response stream? That gives you the size of the HTTP body and thus the
size of the rendered HTML page.

Cheers,
 
Hi Joerg,

I thought that was what I was accomplishing when I did this code....

HttpApplication myHttpApplication = (HttpApplication)sender;
Stream baseStream = myHttpApplication.Response.Filter;
orginalSize = baseStream.Length; //exception here!

But all I got was an exception that "Length" was unsupported? Any
suggestions?

Thanks
Mark
 
Mark said:
Hi Joerg,

I thought that was what I was accomplishing when I did this code....

HttpApplication myHttpApplication = (HttpApplication)sender;
Stream baseStream = myHttpApplication.Response.Filter;
orginalSize = baseStream.Length; //exception here!

But all I got was an exception that "Length" was unsupported? Any
suggestions?

I thought of implementing a Stream Decorator, which wraps a real stream
and simply counts all bytes passed to its Write() method(s) before
calling the underlying stream's Write().

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top