HTML / ASPX image

I

i. Wiin

I'm under the impression that the src element of the <img tab needs to point
to either a .gif file or a .jpg file, not to the httpresponse of a aspx
page.
 
K

Kevin Spencer

I'm under the impression that the src element of the <img tab needs to
point
to either a .gif file or a .jpg file, not to the httpresponse of a aspx
page.

Well, you're under the wrong impression. An ASPX page can indeed serve an
image, and can indeed be used in an image tag.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
K

Kevin Spencer

I check out the URL you posted: no image. Did you swap out the real URL for
a fake one? It's kind of hard to help in that case. Can you post the real
URL? The first thing I want to make sure of is that the page is really
returning an image. It may be returning HTML that contains an image tag,
wich would be wrong. Can't tell without the URL.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
H

Hans Kesting

tma said:
I have the following HTML in use on my web page. I need it to show a
graphic image on the page but do not know what to use in the
codebehind to make the graphic appear. If I load the source url in a
browser by itself, the graphic appears, but when I use the tag in a
web page it does not. Anyone have a suggestion for VB?

<img
src='http://www.domain.com/MohawkWS/MohawkHitCounter.aspx?ItemID=7103830413'
border=0 alt>

This method should work. It's not required to use the "correct" extension
as others suggested, as long as you set the correct contenttype
(image/gif, image/jpeg, ..). See Response.ContentType.

Did something go wrong with the post? I noticed that you seemed to have
no space before "border" and no value for "alt".

Hans Kesting
 
K

Ken Dopierala Jr.

Hi Kevin,

This is good to know. How do you return an image or maybe other type of
file from an ASPX page? The reason I'm asking is that Forms Authentication
seems to only protect ASPX pages and using this it could be used to force
people to log in who are trying to go directly to something other than an
ASPX page. Thanks! Ken.
 
K

Kevin Spencer

Hi Ken,
This is good to know. How do you return an image or maybe other type of
file from an ASPX page?

An ASPX Page class is an HttpHandler. It handles HTTP requests. It can
therefore handle a request for an image. The page gets the image in one of a
large variety of ways (builds it, fetches it, etc), sets the
Response.ContentType to "image/jpg" (or whatever MIME type you are working
with), and then saves the image to the Response.OutputStream. You can then
reference the page in an image tag. Example:

<img src="image.aspx?modificationParameter=value">

Note that, since it is an ASPX page, you can pass additional data to it via
the QueryString, for modifying the image, or whatever you need.
The reason I'm asking is that Forms Authentication
seems to only protect ASPX pages and using this it could be used to force
people to log in who are trying to go directly to something other than an
ASPX page.

Having a hard time figuring this one out, but if I understand you correctly,
yes, it could.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
J

Joerg Jooss

Ken said:
Hi Kevin,

This is good to know. How do you return an image or maybe other type
of file from an ASPX page?

Technically, what you need to do is set the appropriate Content-Type header,
ideally Content-Length as well, and write your binary content to the
response's output stream.

In real world applications, I'd rather use a dedicated HttpHandler for
delivering images and such, because you hardly want all the Page processing
overhead for these specialized "content providers".

Cheers,
 
T

tma

Kevin, what does the code behind look like that sets the response type and
saves the image to the output stream?

Please!
 

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

Top