HttpHandler fire only if file doesn't exist

后端 未结 3 869
长情又很酷
长情又很酷 2021-02-09 09:11

I\'m trying to create a HTTP handler to handle all requests to a folder but I only want it to fire if the files requested don\'t exist (EG: Request comes in for file X, if X exi

3条回答
  •  暖寄归人
    2021-02-09 09:56

    If you would prefer to not create an HttpModule, I can think of two hacks:

    1. Use something like mod-rewrite on Apache or II7 rewrite on IIS to allow specific URLs that exist to go through, take anything else and redirect it to your static file. This could be a large list and I would only recommend implementing this hack if you only have a small number of files.
    2. Change your URL structure to support a routing script that can check to see if the file exists and return it when appropriate. This approach will likely affect caching, so please use caution.

    Jacob

提交回复
热议问题