Reputation: 3298
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?
Upvotes: 6
Views: 1985
Reputation: 1242
Why do you need to do this in that way? Wouldn't it be easier to just use ASP.NET provider and protect this folder with required login? A simple webconfig with logic to access/deny would solve your issue. When someone tries to browse that directory, it will be impossible to download the file and will be redirected to the login page. Let me know if I misunderstood something.
Upvotes: 1
Reputation: 1314
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>
Upvotes: 6
Reputation: 149538
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>
Upvotes: 5