How can I, when executing a controller action, take a Uri (not the one requested) and invoke the action from the controller that would have been executed had that Uri been the one that was called? I can’t simply redirect to that action as I need it to happen in the same request context.
Share
Assuming you have access to the HttpContext (and I suppose you do since you are asking) you could:
Personally I use this approach for handling errors inside my application. I put this in
Application_Errorand execute an error controller for custom error pages staying in the context of the initial HTTP request. You could also place complex objects inside therouteDatahash and you will get those complex objects back as action parameters. I use this to pass the actual exception that occurred to the error controller action.UPDATE:
In order to parse an URL to its route data tokens taking into account current routes you could: