locked
HttpHandler to handle requests to directory or subdirectories (etc) RRS feed

  • Question

  • User-565895123 posted

    Hi all,

    Written a little handler to stop browsing to certain assets. I have a folder called 'assets' and I would like to route all requests for files within that directory or sub directories through the handler. I think I'm looking for the correct syntax for the web.config HttpHandlers section.

    Placing files within the root of assets and using:

    <add verb="GET" path="assets/*.*" type="AssetShieldSite.AssetShield"/>

    works fine but doesn't work when accessing a subdirectory of assets. Have tried

    <add verb="GET" path="assets/*" type="AssetShieldSite.AssetShield"/>

    which didn't work.

    Sorry if this has been asked before but a good search didn't get me an answer.

    (Note: adding all subdirectories involved to the web.config file is a non-starter for me as the application allows the admin to configure access to certain directories - and those directories will change - and the permissions scheme is not as simple as access or not. So I'm looking for a way of passing any request from assets -> downwards, to the handler where it can then inspect the request and retreive permissions from the database to decide whether to allow access or not - based on certain criteria. The handler itsself does all of this and works fine, it purely the mechanism of getting it to recognise any request within assets - no matter how deeply nested - that I need).

    Thanks.

    Tuesday, June 9, 2009 9:45 AM

Answers

  • User1779468316 posted

    I'm telling you from personal experince that you'll be better able to accomplish what you want with an HttpModule better than you'll be able to with an HttpHandler.

    Here's why:

    An HttpModule can inspect every url a visitor to your site requests. For some it can perform work, and for others it can return without doing much at all.

    An HttpHandler is designed to handle a specific type of request, usually a custom file extension.

    From your description and your note at the end, it's obvious to anybody with the proper hindsight that you need to use an HttpModule if you want more success.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 10, 2009 4:10 PM

All replies

  • User1779468316 posted

    I'm telling you from personal experince that you'll be better able to accomplish what you want with an HttpModule better than you'll be able to with an HttpHandler.

    Here's why:

    An HttpModule can inspect every url a visitor to your site requests. For some it can perform work, and for others it can return without doing much at all.

    An HttpHandler is designed to handle a specific type of request, usually a custom file extension.

    From your description and your note at the end, it's obvious to anybody with the proper hindsight that you need to use an HttpModule if you want more success.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 10, 2009 4:10 PM
  • User-565895123 posted

    Thanks very much for that. Spent the morning reading up and I agree completely this sounds like a plan.

    Thanks again.

    Thursday, June 11, 2009 8:03 AM