views:

421

answers:

4

Is it possible to intercept requests in the ASP.NET MVC Framework (beta 1) in order to interact and inspect them?

I need to attach some logging and in some cases dynamically work out if the URL needs authorizing (like applying the Authorize attribute - but at run-time).

+2  A: 

Standard HttpModules work just fine.

You can also choose to add your own custom IRouteHandler, and specifically register routes with that (or hijack the current route definitions and replace them with your route handler).

This should give you the flexibility you need.

Ben Scheirman
+4  A: 

Use ASP.NET MVC Action Filters

JarrettV
+1  A: 

Filters in MVC are applied at compile time, but executed at runtime. You could implement a custom auth filter that would inspect the URL and selectively authorize. It would probably help if you provided more specifics of the scenario you're trying to accomplish.

Haacked
A: 

I use an O/R mapper, that can reload objects from the DB in a generic manner. I would like to be able to intercept the request prior to the creation of the mapped objects, in order to reload them. This would have otherwise have had to be done by the action method, or some other method it may calls. And that is not where I thought this code belongs. I looked at the overridable methods of the Controller, but found nothing obvious that caught my eyes. Does any one know of a way to do this?