I want to modify the controller such that all requests from the web interface call my method without having to modify every page. The idea is to dynamically execute some code on every page request, like middleware on frameworks like Django. There may or may not be any code registered for every request, but I want to be able to execute code registered for any request path.
The first tag of the question is "Angular" so I assume method you want to call is also in Angular. For such a purpose you can use http interceptor. It will be called before each http request your app made and you can place there whatever you want.