468,272 Members | 2,171 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

How to Get Size of HTTP Response Going Back To Client

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.Le ngth; //fails

}

Nov 17 '05 #1
5 5934
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]
- mv*@spam.guard.caspershouse.com

"Mark Overstreet" <Mark Ov********@discussions.microsoft.com> wrote in
message news:B9**********************************@microsof t.com...
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.Le ngth; //fails

}

Nov 17 '05 #2
So there is no way to do this in C#??? Thanks.

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Mark Overstreet" <Mark Ov********@discussions.microsoft.com> wrote in
message news:B9**********************************@microsof t.com...
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.Le ngth; //fails

}


Nov 17 '05 #3
Mark Overstreet wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #4
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

"Joerg Jooss" wrote:
Mark Overstreet wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 17 '05 #5
Mark Overstreet wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by dondiego | last post: by
7 posts views Thread by Michael Foord | last post: by
12 posts views Thread by David Sworder | last post: by
6 posts views Thread by MattC | last post: by
19 posts views Thread by jeremyz | last post: by
2 posts views Thread by pmlane2001 | last post: by
7 posts views Thread by =?Utf-8?B?Um9iIFRob21zb24=?= | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.