5

How can I capture and handle static file requests with asp.net?

I've tried the "IModule" and "Global.asax" with BeginRequest but the request is not captured.

Is there some setting in IIS to direct some Component (IModule / Handler / Global.asax / DLL) in asp.net?

Or some way to direct requests to some DLL made with C #?

For example: "get http://localhost/myapp/report/report1.html"

How can I capture this request?

I could not do, get in asp.net.

I want to be able to check the permission, and can handle the file, and handle the response.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • You may also want to take a look at [How do I protect static files with ASP.NET form auhentication on IIS 7.5?](http://stackoverflow.com/q/2903292/33051) – Zhaph - Ben Duguid Jan 14 '15 at 10:54

2 Answers2

5

The simplest way if you are running the Application Pool in Integrated mode is to tell IIS to send all requests to the "Managed Handlers".

In your web.config you should have a <system.webServer> element which may have a modules element - update that to:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
  [...]

With that in place you'll be able to use all the standard features of ASP.NET including authentication control on paths.

Note that this will send all requests through your application, so you'll see requests for .css and .js files in there as well so if you do try locking everything down you'll need to leave those open.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
1

Yes, IIS has such setting, Handler Mapping.

The setting determines with handlers would be called for different file extensions. Set the ASP.NET handler to desired extensions, and the you can use ASP.NET features (IHttpModel and other) to capture.

Mark Shevchenko
  • 7,937
  • 1
  • 25
  • 29