473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 6910
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dondiego | last post by:
Hello Everybody Im going to develop a multiplayer game. I will use a servlet and an applet on the client side. I see two possible ways to mantain the contact between the clients and the server:...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
3
by: PorkyJr | last post by:
Running an asp page that has the following code: <% response.Write MonthName(Month(date)) %> &nbsp; <% response.Write Day(date) %> ,
12
by: David Sworder | last post by:
Hi, I'm writing an application in which a client (C#/WinForms) and server (C#/service) interact with one another. The client establishes a "session" with the server but for scalability reasons...
6
by: MattC | last post by:
I used a trace tool (YATT) to see the size of my pages coming down the network. The page sizes were ok coming in at about 3K per page, but I noticed the bytes out column was 20K. Some of my users...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
19
by: jeremyz | last post by:
Hi all, I am not a developer, but I work with several and am posting this for them. We are trying to determine whether it is possible to check the size of a file before a user uploads it. ...
2
by: pmlane2001 | last post by:
I have a PHP SOAP XML file size problem that I was wondering if anyone has seen before. I have an XML file that when I put it through my PHP script with 270 lines (13,082 KB) it works fine. If I...
7
by: =?Utf-8?B?Um9iIFRob21zb24=?= | last post by:
Hi is there a way in asp.net 1.1 to in code behind query the page size that is generated, I realise IIS does it as it has that data in the logs, I would like to capture this data so that I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.