Reputation: 69915
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?
Upvotes: 4
Views: 310
Reputation: 146630
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
or PostAuthorizeRequest
event to do your URL registration as the routing happens after that
The Url routing happens just after PostAuthorizeRequest
event and since the routes will already be registered, the first request will also be served fine.
Upvotes: 2
Reputation: 9470
This is a kind of pseudocode
which you can use in Global.asax
.
private bool RootIsRegistered = false; //register Application level var
void Application_BeginRequest(object sender,EventArgs e){
if(!RootIsRegistered)
RegisterRoots();
}
This way you can be sure that your roots are registered even at the first request.
Upvotes: 1