would this be a possible use of an HTTPHandler?

Discussion in 'ASP .Net' started by Steve, Jan 11, 2004.

  1. Steve

    Steve Guest

    let's say that I have a webpage with an <img> tag and it has an invalid src
    attribute, that is the image it points to doesn't exist. Is there any way
    to catch stuff like that and handle it? For example, if I detect a missing
    image, I could instead return a NoImageAvail.jpg image instead?

    Weird question and I'm not sure how to ask it, but I suspect it could be
    something that could be handled somehow. Thanks.

    Steve
    Steve, Jan 11, 2004
    #1
    1. Advertising

  2. Steve

    Hermit Dave Guest

    The way i store images... most important ones are stored in the database...
    as a byte array...
    i extract them on db call and i check them for a null value... null would
    mean not there....
    if you are storing them in on hard drive... you can still use a stream
    reader to read it from the hard drive into memory... instead of using a
    plain vanilla <img tag>

    in that case what you will need to do is check the hdd for image... if found
    read it from a hard drive.. into a memory stream... and output it to client
    page....

    http://www.microsoft.com/belux/nl/msdn/community/columns/desmet/httphandler.mspx

    this link is a good example on how to use custom http handler to create a
    file that serves images....

    you can then use <img src"the image serving file.ext?your params"> to fetch
    the image... (plus you can use caching to image on server etc... to make it
    faster)

    Note: you can do away by just create an aspx page that does the job.. but
    you dont need to (infact custom handler would be about 5% faster)

    --
    Regards,

    HD

    "Steve" <> wrote in message
    news:...
    > let's say that I have a webpage with an <img> tag and it has an invalid

    src
    > attribute, that is the image it points to doesn't exist. Is there any way
    > to catch stuff like that and handle it? For example, if I detect a

    missing
    > image, I could instead return a NoImageAvail.jpg image instead?
    >
    > Weird question and I'm not sure how to ask it, but I suspect it could be
    > something that could be handled somehow. Thanks.
    >
    > Steve
    >
    >
    Hermit Dave, Jan 11, 2004
    #2
    1. Advertising

  3. Steve

    RAMADU Guest


    >-----Original Message-----
    >let's say that I have a webpage with an <img> tag and it

    has an invalid src
    >attribute, that is the image it points to doesn't exist.

    Is there any way
    >to catch stuff like that and handle it? For example, if

    I detect a missing
    >image, I could instead return a NoImageAvail.jpg image

    instead?
    >
    >Weird question and I'm not sure how to ask it, but I

    suspect it could be
    >something that could be handled somehow. Thanks.
    >
    >Steve
    >

    Hi Steve,

    Keep the image as a Server Control. On Page_Load(), check
    if the image source, exists (by using IO and a try catch
    block). On the catch event, make the image source point to
    your NoImageAvail.jpg image.
    NOTE: This process consumes a lot of I/O processing and
    could make you page load slow esp. if you have a lot of
    images.
    RAMADU, Jan 12, 2004
    #3
  4. Steve

    RAMADU Guest


    >-----Original Message-----
    >let's say that I have a webpage with an <img> tag and it

    has an invalid src
    >attribute, that is the image it points to doesn't exist.

    Is there any way
    >to catch stuff like that and handle it? For example, if

    I detect a missing
    >image, I could instead return a NoImageAvail.jpg image

    instead?
    >
    >Weird question and I'm not sure how to ask it, but I

    suspect it could be
    >something that could be handled somehow. Thanks.
    >
    >Steve
    >

    Hi Steve,

    Keep the image as a Server Control. On Page_Load(), check
    if the image source, exists (by using IO and a try catch
    block). On the catch event, make the image source point to
    your NoImageAvail.jpg image.
    NOTE: This process consumes a lot of I/O processing and
    could make you page load slow esp. if you have a lot of
    images.
    RAMADU, Jan 12, 2004
    #4
  5. Yes, that would most certainly be a candidate for an HttpHandler. You can
    write an HttpHandler for all your image requests, and it can do much more
    than just return an image when the image doesn't exist. It could modify or
    generate images in any way you want on the fly, by using QueryStrings as
    well.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Steve" <> wrote in message
    news:...
    > let's say that I have a webpage with an <img> tag and it has an invalid

    src
    > attribute, that is the image it points to doesn't exist. Is there any way
    > to catch stuff like that and handle it? For example, if I detect a

    missing
    > image, I could instead return a NoImageAvail.jpg image instead?
    >
    > Weird question and I'm not sure how to ask it, but I suspect it could be
    > something that could be handled somehow. Thanks.
    >
    > Steve
    >
    >
    Kevin Spencer, Jan 12, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zootius
    Replies:
    0
    Views:
    796
    zootius
    Dec 7, 2005
  2. the4man
    Replies:
    5
    Views:
    3,633
    Kevin Spencer
    Mar 2, 2006
  3. Gabriel Lacatus

    Dynamic HttpHandler mapping... possible?

    Gabriel Lacatus, Apr 11, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    628
    Steven Cheng[MSFT]
    Apr 12, 2006
  4. Jake Barnes
    Replies:
    50
    Views:
    381
    Matej
    Feb 13, 2006
  5. fir
    Replies:
    26
    Views:
    428
    Keith Thompson
    Jun 12, 2013
Loading...

Share This Page