Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write httphandler to only intercept files in a specific folder

I have written a httphandler to intercept all pdf files request via URL from a specific folder and redirect the user to Login page. If the user is authenticated the file can be downloaded. My web.config has the following entry for the interception

<httpHandlers>
 <add verb="*" path="/calderdale/*.pdf"
   type="NES.HiLo.Security.CalderDaleAuthenticationHandler, NES.HiLo.Security" />
</httpHandlers>

In IIS (6.0) Application extension settings I have added a setting with executable C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll and extension Pdf.

This works but every pdf file request is getting intercepted rather the the files present in calderdale directory.

I have tried solutions given on this link Mapping specific folder to HttpHandler in web.config and removed the application extension setting but then handler does get call at all.

Any ideas?

like image 963
rumi Avatar asked Apr 17 '14 14:04

rumi


2 Answers

I think the trick here is to only register the HttpHandler for that specific directory. This can be done by moving the system.web/httpHandlers content into a location node in your web.config. For instance:

<location path="calderdale">  

( system.web/httpHandlers content )

</location>
like image 74
Domin8urMind Avatar answered Sep 21 '22 00:09

Domin8urMind


Add this to your main web config:

<location path="static">
  <system.web>
    <httpHandlers>
      <add verb="GET,HEAD" path="*.*" 
          type="NES.HiLo.Security.CalderDaleAuthenticationHandler, NES.HiLo.Security" />
    </httpHandlers>
  </system.web>    
</location>
like image 41
Yuval Itzchakov Avatar answered Sep 21 '22 00:09

Yuval Itzchakov