Overwrite Url with POST data in Application_AquireRequestState event

I have a code that registers a route in an Application_AcquireRequestStateapplication event . Once the routes are registered, I set the flag at the Http runtime cache so that the route registration code does not execute again. There is a specific reason for registering a route in this event Application_AcquireRequestState.

After restarting the application pool and upon receipt of a request (corresponding to a route), the route registration code is started, but this request is not served by IIS / ASP.Net, and it returns 404. Subsequent valid requests everything works fine.

I want to make sure that even the first request is also correctly executed.

Is it possible to rewrite the request so that after registering the route we can somehow try to reproduce the request if the URL matches one of the registered routes? Is there a solution to solve this problem?

+4
source share
2 answers

As below

order of events

and below

events

And the bottom stream SO

When is pipelining routed?

You may need to target the event AuthenticateRequestor PostAuthorizeRequestto register the URL, as routing happens after that

Url routing occurs immediately after the event PostAuthorizeRequest, and since the routes have already been registered, the first request will also be served in order.

+2
source

pseudocode, Global.asax.

private bool RootIsRegistered = false; //register Application level var

void Application_BeginRequest(object sender,EventArgs e){
   if(!RootIsRegistered)
      RegisterRoots();
}

, , .

+1

Source: https://habr.com/ru/post/1685987/


All Articles