本文介绍了在Application_AquireRequestState事件中用POST数据重写Url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,用于在应用程序的 Application_AcquireRequestState 事件中注册路由.一旦路由被注册,我将在Http运行时缓存中设置一个标志,以便不再执行路由注册代码.在此事件 Application_AcquireRequestState 中有特定的原因注册路由.

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.

一旦重新启动应用程序池,并且如果传入了有效(与路由匹配)请求,则路由注册代码会启动,但IIS/ASP.Net不会处理该请求,它会返回404.后续的有效请求是一切正常.

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.

是否可以重写请求,以便在路由注册完成后,如果url与已注册的路由之一匹配,我们可以以某种方式尝试重播请求?有解决这个问题的解决方案吗?

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?

推荐答案

如下所示

及以下

下面的SO线程

何时在管道中进行路由?

您可能需要将目标定位在 AuthenticateRequest PostAuthorizeRequest 事件之间,以进行URL注册,因为在此之后发生路由

You may need to target something between AuthenticateRequest or PostAuthorizeRequest event to do your URL registration as the routing happens after that

Url路由仅在 PostAuthorizeRequest 事件之后发生,并且由于路由已被注册,因此第一个请求也将得到很好的服务.

The Url routing happens just after PostAuthorizeRequest event and since the routes will already be registered, the first request will also be served fine.

这篇关于在Application_AquireRequestState事件中用POST数据重写Url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:26