I have a code which registers the route in Application_AcquireRequestState
event of the application. Once the routes are registered, I set a flag in the Http runtime cache so that I don't execute the route registration code again. There is a specific reason to register the route in this event Application_AcquireRequestState
.
Once the app pool is restarted and if a valid(matching the route) request comes in, the route registration code kicks in but that request is not served by IIS/ASP.Net and it returns 404. The subsequent valid requests are all working fine.
I want to make sure even the first request is also served correctly.
Is it possible to rewrite the request so that after the route registration is done we can somehow try to replay the request if the url matches with one of the route that are registered? Is there any solution to solve this problem?
As per below
and below
And the below SO thread
When does routing take place in the pipeline?
You may need to target something between
AuthenticateRequest
orPostAuthorizeRequest
event to do your URL registration as the routing happens after thatThe Url routing happens just after
PostAuthorizeRequest
event and since the routes will already be registered, the first request will also be served fine.This is a kind of
pseudocode
which you can use inGlobal.asax
.This way you can be sure that your roots are registered even at the first request.