Using global.asax to protect images?

Discussion in 'ASP .Net' started by Bill, May 24, 2006.

  1. Bill

    Bill Guest

    Anyone have any success in using global.asax to protect images in a folder from being
    linked to by external websites?

    I'd tried to use global.asa in the past, with no success. Any help would be appreciated.

    THANKS,

    Bill.
    Bill, May 24, 2006
    #1
    1. Advertising

  2. I don't believe this can be done in the global.asax. I'm not sure that this
    is the only way to accomplish this, but at least one method would be to
    create a custom HttpHandler for all image requests. When an image is
    requested the HttpHandler can look at the
    Request.Servervariables["HTTP_REFERER"] to ascertain that the request is
    being referred from a page in the web itself, and redirect or take
    appropriate action to not deliver the image if the HttpReferer is not in the
    web's domain.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Numbskull

    If the truth hurts, wear it.

    "Bill" <> wrote in message
    news:...
    > Anyone have any success in using global.asax to protect images in a folder
    > from being
    > linked to by external websites?
    >
    > I'd tried to use global.asa in the past, with no success. Any help would
    > be appreciated.
    >
    > THANKS,
    >
    > Bill.
    >
    >
    Kevin Spencer, May 25, 2006
    #2
    1. Advertising

  3. Bill

    vMike Guest

    "Bill" <> wrote in message
    news:...
    > Anyone have any success in using global.asax to protect images in a folder

    from being
    > linked to by external websites?
    >
    > I'd tried to use global.asa in the past, with no success. Any help would

    be appreciated.
    >
    > THANKS,
    >
    > Bill.
    >


    Another idea that I have used with reasonable success is to have the image
    url set to .aspx file and have the .aspx save the image to the
    Response.OutputStream. You can exercise quite a bit of control over what
    gets streamed depending on referrer conditions or cookie conditions. You can
    also resize images on the fly, add text, etc (using system.drawing.image).
    It doesn't stop someone from right clicking and saving the image, but it
    does stop bots from getting the images. It does add some processing time so
    I only do it for high quality images and if a bot come through, I just give
    them a thumbnail.

    Mike


    Hope this helps.
    vMike, May 25, 2006
    #3
  4. Bill

    Bill Guest

    Hi, Kevin:

    Yea, I looked into using a custom HttpHandler in my web.config. However, all the
    examples I've seen require creating a .DLL, and although I own a copy of Visual Basic 6,
    creating .DLLs is outside of my area of expertise.

    Unless... is there a way for HttpHandler to be associated with a .aspx page instead?

    Thanks,

    Bill.


    "Kevin Spencer" wrote..
    > I don't believe this can be done in the global.asax. I'm not sure that this
    > is the only way to accomplish this, but at least one method would be to
    > create a custom HttpHandler for all image requests. When an image is
    > requested the HttpHandler can look at the
    > Request.Servervariables["HTTP_REFERER"] to ascertain that the request is
    > being referred from a page in the web itself, and redirect or take
    > appropriate action to not deliver the image if the HttpReferer is not in the
    > web's domain.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > Professional Numbskull
    >
    > If the truth hurts, wear it.
    >
    > "Bill" wrote...
    > > Anyone have any success in using global.asax to protect images in a folder
    > > from being
    > > linked to by external websites?
    > >
    > > I'd tried to use global.asa in the past, with no success. Any help would
    > > be appreciated.
    > >
    > > THANKS,
    > >
    > > Bill.
    > >
    > >

    >
    >
    Bill, May 25, 2006
    #4
  5. Hi Bill,

    Just because you can't compile a DLL doesn't mean you can't use a class. If
    you're using ASP.Net 2.0, you can create a .cs (or .vb) file with a class
    definition in it and deploy it to your /app_code directory.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Numbskull

    This is, by definition, not that.

    "Bill" <> wrote in message
    news:...
    > Hi, Kevin:
    >
    > Yea, I looked into using a custom HttpHandler in my web.config. However,
    > all the
    > examples I've seen require creating a .DLL, and although I own a copy of
    > Visual Basic 6,
    > creating .DLLs is outside of my area of expertise.
    >
    > Unless... is there a way for HttpHandler to be associated with a .aspx
    > page instead?
    >
    > Thanks,
    >
    > Bill.
    >
    >
    > "Kevin Spencer" wrote..
    >> I don't believe this can be done in the global.asax. I'm not sure that
    >> this
    >> is the only way to accomplish this, but at least one method would be to
    >> create a custom HttpHandler for all image requests. When an image is
    >> requested the HttpHandler can look at the
    >> Request.Servervariables["HTTP_REFERER"] to ascertain that the request is
    >> being referred from a page in the web itself, and redirect or take
    >> appropriate action to not deliver the image if the HttpReferer is not in
    >> the
    >> web's domain.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Professional Numbskull
    >>
    >> If the truth hurts, wear it.
    >>
    >> "Bill" wrote...
    >> > Anyone have any success in using global.asax to protect images in a
    >> > folder
    >> > from being
    >> > linked to by external websites?
    >> >
    >> > I'd tried to use global.asa in the past, with no success. Any help
    >> > would
    >> > be appreciated.
    >> >
    >> > THANKS,
    >> >
    >> > Bill.
    >> >
    >> >

    >>
    >>

    >
    >
    Kevin Spencer, May 26, 2006
    #5
  6. Bill

    Bill Guest

    Kevin, although I rock in Classic ASP, I'm new to ASP.NET. I'm a quick study on ASP.NET,
    but I've never done a class before.

    Could you point me to a beginner reference so that I can teach myself what you are
    recommending?

    Thanks!

    Bill.


    "Kevin Spencer" <> wrote in message
    news:...
    > Hi Bill,
    >
    > Just because you can't compile a DLL doesn't mean you can't use a class. If
    > you're using ASP.Net 2.0, you can create a .cs (or .vb) file with a class
    > definition in it and deploy it to your /app_code directory.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > Professional Numbskull
    >
    > This is, by definition, not that.
    >
    > "Bill" <> wrote in message
    > news:...
    > > Hi, Kevin:
    > >
    > > Yea, I looked into using a custom HttpHandler in my web.config. However,
    > > all the
    > > examples I've seen require creating a .DLL, and although I own a copy of
    > > Visual Basic 6,
    > > creating .DLLs is outside of my area of expertise.
    > >
    > > Unless... is there a way for HttpHandler to be associated with a .aspx
    > > page instead?
    > >
    > > Thanks,
    > >
    > > Bill.
    > >
    > >
    > > "Kevin Spencer" wrote..
    > >> I don't believe this can be done in the global.asax. I'm not sure that
    > >> this
    > >> is the only way to accomplish this, but at least one method would be to
    > >> create a custom HttpHandler for all image requests. When an image is
    > >> requested the HttpHandler can look at the
    > >> Request.Servervariables["HTTP_REFERER"] to ascertain that the request is
    > >> being referred from a page in the web itself, and redirect or take
    > >> appropriate action to not deliver the image if the HttpReferer is not in
    > >> the
    > >> web's domain.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> Professional Numbskull
    > >>
    > >> If the truth hurts, wear it.
    > >>
    > >> "Bill" wrote...
    > >> > Anyone have any success in using global.asax to protect images in a
    > >> > folder
    > >> > from being
    > >> > linked to by external websites?
    > >> >
    > >> > I'd tried to use global.asa in the past, with no success. Any help
    > >> > would
    > >> > be appreciated.
    > >> >
    > >> > THANKS,
    > >> >
    > >> > Bill.
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Bill, May 27, 2006
    #6
  7. Wonder why you choose for global.asax ?
    If the image is obtained through a generic handler (and simply streamed),
    you could decide to set a tag in it's session to allow the user.
    Afaik this should be possible.

    Even so, the generic handler can be called with parameters, these could be
    temporary.




    "Bill" <> schreef in bericht
    news:...
    > Kevin, although I rock in Classic ASP, I'm new to ASP.NET. I'm a quick
    > study on ASP.NET,
    > but I've never done a class before.
    >
    > Could you point me to a beginner reference so that I can teach myself what
    > you are
    > recommending?
    >
    > Thanks!
    >
    > Bill.
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    >> Hi Bill,
    >>
    >> Just because you can't compile a DLL doesn't mean you can't use a class.
    >> If
    >> you're using ASP.Net 2.0, you can create a .cs (or .vb) file with a class
    >> definition in it and deploy it to your /app_code directory.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Professional Numbskull
    >>
    >> This is, by definition, not that.
    >>
    >> "Bill" <> wrote in message
    >> news:...
    >> > Hi, Kevin:
    >> >
    >> > Yea, I looked into using a custom HttpHandler in my web.config.
    >> > However,
    >> > all the
    >> > examples I've seen require creating a .DLL, and although I own a copy
    >> > of
    >> > Visual Basic 6,
    >> > creating .DLLs is outside of my area of expertise.
    >> >
    >> > Unless... is there a way for HttpHandler to be associated with a .aspx
    >> > page instead?
    >> >
    >> > Thanks,
    >> >
    >> > Bill.
    >> >
    >> >
    >> > "Kevin Spencer" wrote..
    >> >> I don't believe this can be done in the global.asax. I'm not sure that
    >> >> this
    >> >> is the only way to accomplish this, but at least one method would be
    >> >> to
    >> >> create a custom HttpHandler for all image requests. When an image is
    >> >> requested the HttpHandler can look at the
    >> >> Request.Servervariables["HTTP_REFERER"] to ascertain that the request
    >> >> is
    >> >> being referred from a page in the web itself, and redirect or take
    >> >> appropriate action to not deliver the image if the HttpReferer is not
    >> >> in
    >> >> the
    >> >> web's domain.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> Professional Numbskull
    >> >>
    >> >> If the truth hurts, wear it.
    >> >>
    >> >> "Bill" wrote...
    >> >> > Anyone have any success in using global.asax to protect images in a
    >> >> > folder
    >> >> > from being
    >> >> > linked to by external websites?
    >> >> >
    >> >> > I'd tried to use global.asa in the past, with no success. Any help
    >> >> > would
    >> >> > be appreciated.
    >> >> >
    >> >> > THANKS,
    >> >> >
    >> >> > Bill.
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Edwin Knoppert, May 27, 2006
    #7
  8. Hi Bill,

    Here's a good one:

    http://geekswithblogs.net/flanakin/articles/HttpHandlers.aspx

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Numbskull

    This is, by definition, not that.

    "Bill" <> wrote in message
    news:...
    > Kevin, although I rock in Classic ASP, I'm new to ASP.NET. I'm a quick
    > study on ASP.NET,
    > but I've never done a class before.
    >
    > Could you point me to a beginner reference so that I can teach myself what
    > you are
    > recommending?
    >
    > Thanks!
    >
    > Bill.
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    >> Hi Bill,
    >>
    >> Just because you can't compile a DLL doesn't mean you can't use a class.
    >> If
    >> you're using ASP.Net 2.0, you can create a .cs (or .vb) file with a class
    >> definition in it and deploy it to your /app_code directory.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Professional Numbskull
    >>
    >> This is, by definition, not that.
    >>
    >> "Bill" <> wrote in message
    >> news:...
    >> > Hi, Kevin:
    >> >
    >> > Yea, I looked into using a custom HttpHandler in my web.config.
    >> > However,
    >> > all the
    >> > examples I've seen require creating a .DLL, and although I own a copy
    >> > of
    >> > Visual Basic 6,
    >> > creating .DLLs is outside of my area of expertise.
    >> >
    >> > Unless... is there a way for HttpHandler to be associated with a .aspx
    >> > page instead?
    >> >
    >> > Thanks,
    >> >
    >> > Bill.
    >> >
    >> >
    >> > "Kevin Spencer" wrote..
    >> >> I don't believe this can be done in the global.asax. I'm not sure that
    >> >> this
    >> >> is the only way to accomplish this, but at least one method would be
    >> >> to
    >> >> create a custom HttpHandler for all image requests. When an image is
    >> >> requested the HttpHandler can look at the
    >> >> Request.Servervariables["HTTP_REFERER"] to ascertain that the request
    >> >> is
    >> >> being referred from a page in the web itself, and redirect or take
    >> >> appropriate action to not deliver the image if the HttpReferer is not
    >> >> in
    >> >> the
    >> >> web's domain.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> Professional Numbskull
    >> >>
    >> >> If the truth hurts, wear it.
    >> >>
    >> >> "Bill" wrote...
    >> >> > Anyone have any success in using global.asax to protect images in a
    >> >> > folder
    >> >> > from being
    >> >> > linked to by external websites?
    >> >> >
    >> >> > I'd tried to use global.asa in the past, with no success. Any help
    >> >> > would
    >> >> > be appreciated.
    >> >> >
    >> >> > THANKS,
    >> >> >
    >> >> > Bill.
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Kevin Spencer, May 28, 2006
    #8
  9. Bill

    Bill Guest

    Excellent, thanks Kevin!

    Bill.


    "Kevin Spencer" wrote...
    > Hi Bill,
    >
    > Here's a good one:
    >
    > http://geekswithblogs.net/flanakin/articles/HttpHandlers.aspx
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > Professional Numbskull
    >
    > This is, by definition, not that.
    >
    > "Bill" wrote...
    > > Kevin, although I rock in Classic ASP, I'm new to ASP.NET. I'm a quick
    > > study on ASP.NET,
    > > but I've never done a class before.
    > >
    > > Could you point me to a beginner reference so that I can teach myself what
    > > you are
    > > recommending?
    > >
    > > Thanks!
    > >
    > > Bill.
    > >
    > >
    > > "Kevin Spencer" wrote...
    > >> Hi Bill,
    > >>
    > >> Just because you can't compile a DLL doesn't mean you can't use a class.
    > >> If
    > >> you're using ASP.Net 2.0, you can create a .cs (or .vb) file with a class
    > >> definition in it and deploy it to your /app_code directory.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> Professional Numbskull
    > >>
    > >> This is, by definition, not that.
    > >>
    > >> "Bill" wrote...
    > >> > Hi, Kevin:
    > >> >
    > >> > Yea, I looked into using a custom HttpHandler in my web.config.
    > >> > However,
    > >> > all the
    > >> > examples I've seen require creating a .DLL, and although I own a copy
    > >> > of
    > >> > Visual Basic 6,
    > >> > creating .DLLs is outside of my area of expertise.
    > >> >
    > >> > Unless... is there a way for HttpHandler to be associated with a .aspx
    > >> > page instead?
    > >> >
    > >> > Thanks,
    > >> >
    > >> > Bill.
    > >> >
    > >> >
    > >> > "Kevin Spencer" wrote..
    > >> >> I don't believe this can be done in the global.asax. I'm not sure that
    > >> >> this
    > >> >> is the only way to accomplish this, but at least one method would be
    > >> >> to
    > >> >> create a custom HttpHandler for all image requests. When an image is
    > >> >> requested the HttpHandler can look at the
    > >> >> Request.Servervariables["HTTP_REFERER"] to ascertain that the request
    > >> >> is
    > >> >> being referred from a page in the web itself, and redirect or take
    > >> >> appropriate action to not deliver the image if the HttpReferer is not
    > >> >> in
    > >> >> the
    > >> >> web's domain.
    > >> >>
    > >> >> --
    > >> >> HTH,
    > >> >>
    > >> >> Kevin Spencer
    > >> >> Microsoft MVP
    > >> >> Professional Numbskull
    > >> >>
    > >> >> If the truth hurts, wear it.
    > >> >>
    > >> >> "Bill" wrote...
    > >> >> > Anyone have any success in using global.asax to protect images in a
    > >> >> > folder
    > >> >> > from being
    > >> >> > linked to by external websites?
    > >> >> >
    > >> >> > I'd tried to use global.asa in the past, with no success. Any help
    > >> >> > would
    > >> >> > be appreciated.
    > >> >> >
    > >> >> > THANKS,
    > >> >> >
    > >> >> > Bill.
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Bill, May 31, 2006
    #9
    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. VSK
    Replies:
    1
    Views:
    767
    Alvin Bruney
    Jul 29, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    6,857
    Daniel Bass
    Dec 31, 2003
  3. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    801
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  4. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,138
    Mark Rae
    May 23, 2006
  5. OK
    Replies:
    5
    Views:
    611
    Peter Bromberg [C# MVP]
    Nov 26, 2007
Loading...

Share This Page