Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 4 intercept all incoming requests

Is there a way for me to catch all incoming requests to my ASP.NET MVC 4 app and run some code before continuing the request onward to the specified controller/action?

I need to run some custom auth code with existing services, and to do this properly, I'll need to be able intercept all incoming requests from all clients to double check some things with the other service.

like image 690
Jesse Avatar asked Jul 30 '12 17:07

Jesse


1 Answers

The most correct way would be to create a class that inherits ActionFilterAttribute and override OnActionExecuting method. This can then be registered in the GlobalFilters in Global.asax.cs

Of course, this will only intercept requests that actually have a route.

like image 102
Yngve B-Nilsen Avatar answered Sep 22 '22 13:09

Yngve B-Nilsen