473,508 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Question! - Streaming a small image to the browser in c#

I've seen several posts around the Internet and many of them either
don't work or only partially work. All I'm trying to do is record some
action asynchronously from an html file, a sort of logging mechanism.
The product is a CD catalog that will be delivered to many customers
and they want the ability to log specific pages accross the Internet,
and there's no gaurantee these people will be connected to the
Internet, the ones that are though, we want to log their actions. I've
done something similar in COM a while ago, but can't get it to work in
..NET.

Thus, i will put an 1 X 1 pixel image tag at the bottom of each page I
want logged. I'm also going to pass querystring information, which is
all perfectly legal in HTML as long as your output is binary.

<img src="http://www.domain.com/log.aspx?a=33&b=467">

All I'm trying to do is write the log.aspx page to simply return an
image that I have stored on my webserver. it should return the same
1X1 transparent image every time. Behind the scenes, the aspx page
will log the querystring info to the db (this part's done).

Here's the best way I've got it to work (code is simplified to
relevant parts), but it has 2 problems: 1) it creates the image on the
fly (don't think that's necessary) and 2) the image is not transparent
(even after setting many settings on the bitmap object).

private void Page_Load(object sender, System.EventArgs e)
{
Bitmap bitmap = new Bitmap(1, 1);
try
{
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
catch {}
finally
{
bitmap.Dispose();
}
}

I'm guessing there's a simpler (much different) way to achieve this.
That is, load an image from the fileserver and spit it out to the
window. I've spent several hours messing around with stream objects
and such, but can't find the right way...

Thanks, in advance, for any help!

-dave
Nov 15 '05 #1
4 2816
here's the logic, too lazy to write cod

1. have a 1x1 transparent gif on file serve
2. Open gif as Fil
3. read bytes from FileStrea
4. write bytes to HttpResponse.OutputStrea
5. set HttpResponse.ContentType to "image/gif

done

a cleaner solution would be to use a IHttpHandler instead of .aspx file. might perform better too since you can reuse a HttpHandler. even better, embed the 1x1 transparent gif with the IHttpHandler assembly, then you got a self contained unit without dependency on external files.
Nov 15 '05 #2
malcolm <ch********@yahoo.com> wrote:

<snip>
All I'm trying to do is write the log.aspx page to simply return an
image that I have stored on my webserver. it should return the same
1X1 transparent image every time.


Why don't you just have it as a web-accessible file then, and don't
bother using ASP.NET at all for that file?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
This article, which I posted some time ago, sounds like it might be pretty
close to what you are looking for:

http://www.eggheadcafe.com/articles/20030516.asp

Peter

"malcolm" <ch********@yahoo.com> wrote in message
news:4f**************************@posting.google.c om...
I've seen several posts around the Internet and many of them either
don't work or only partially work. All I'm trying to do is record some
action asynchronously from an html file, a sort of logging mechanism.
The product is a CD catalog that will be delivered to many customers
and they want the ability to log specific pages accross the Internet,
and there's no gaurantee these people will be connected to the
Internet, the ones that are though, we want to log their actions. I've
done something similar in COM a while ago, but can't get it to work in
.NET.

Thus, i will put an 1 X 1 pixel image tag at the bottom of each page I
want logged. I'm also going to pass querystring information, which is
all perfectly legal in HTML as long as your output is binary.

<img src="http://www.domain.com/log.aspx?a=33&b=467">

All I'm trying to do is write the log.aspx page to simply return an
image that I have stored on my webserver. it should return the same
1X1 transparent image every time. Behind the scenes, the aspx page
will log the querystring info to the db (this part's done).

Here's the best way I've got it to work (code is simplified to
relevant parts), but it has 2 problems: 1) it creates the image on the
fly (don't think that's necessary) and 2) the image is not transparent
(even after setting many settings on the bitmap object).

private void Page_Load(object sender, System.EventArgs e)
{
Bitmap bitmap = new Bitmap(1, 1);
try
{
Response.ContentType = "image/gif";
bitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
catch {}
finally
{
bitmap.Dispose();
}
}

I'm guessing there's a simpler (much different) way to achieve this.
That is, load an image from the fileserver and spit it out to the
window. I've spent several hours messing around with stream objects
and such, but can't find the right way...

Thanks, in advance, for any help!

-dave

Nov 15 '05 #4
Hello Jon, thanks for the feedback, but I think you missed my point in
my original post. I will be passing querystring information that I
must capture and store to the database. Example:

<img src="http://www.domain.com/log.aspx?a=1&b=2">

the file log.aspx needs to:
1) gather all the querystring info and log it to the database (this
can even happen asynch, which is nice)
2) return an image (and only an image).

i won't be able to do #1 if I do what you said (which is the whole
point of this approach)

I'm sure there's several ways to solve this, but this seems like a
very good way. Basically to log info to a remote server on an html
page that originates from a CD (not from a website). The cool thing
about this approach is that images are asynch by nature and the image
is a 1x1 tranparant image (not noticable) at the very end of the html
stream (so the user won't even notice).

thanks,
dave

Jon Skeet [C# MVP] <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>...
malcolm <ch********@yahoo.com> wrote:

<snip>
All I'm trying to do is write the log.aspx page to simply return an
image that I have stored on my webserver. it should return the same
1X1 transparent image every time.


Why don't you just have it as a web-accessible file then, and don't
bother using ASP.NET at all for that file?

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3662
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
3
2148
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how can I programmatically select a node Thanks in Advanc Peter
1
1533
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
4
1424
by: pcnerd | last post by:
I originally asked this question in the "classic" VB forum. It occured to me after I had sent it that I sent it to the wrong forum. Anyway! Here's the situation. I have VB.NET 2005 Express...
4
118780
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
14
2961
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
30
3472
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
2106
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
17
5788
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
7227
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
7127
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...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.