且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将HttpModule .Net类库移植到.Net Core Web API

更新时间:2023-02-16 21:53:52

HTTP模块是经典ASP.NET/IIS应用程序模型的概念。

HTTP Modules are a concept of the classic ASP.NET / IIS application model.

ASP.NET Core不使用IIS的事件系统,则IIS收到的请求将转发到ASP.NET Core应用程序,由该应用程序处理并返回。

ASP.NET Core does not use IIS' event system, the requests that IIS received are forwarded to the ASP.NET Core app, processed by this application and returned.

如果您使用的是web.config中的http模块,不能很好地保证它将有机会在正确的时间处理部分请求/响应。此外,如果模块订购正常,您将无法在IIS外部托管应用程序-您将有效地并行运行ASP.NET Core和ASP.NET。

If you are using an http module inside a web.config, there isn't a good guarantee that it will have a chance to process parts of the request/response at the right times. Also, you will not be able to host the app outside of IIS if you ever get the module ordering working correctly - you would effectively be running ASP.NET Core and ASP.NET side-by-side.

如果要将类似模块的功能移植到ASP.NET Core应用程序,***的起点是中间件。 ASP中的中间件。 NET Core 是处理管道的一部分,它可以在应用程序定义的管道中的一点处处理传入的请求和传出的响应。

If you want to port module-like functionality to an ASP.NET Core app, the best place to start is a Middleware. A middleware in ASP.NET Core is part of the processing pipeline and gets to process incoming requests and outgoing response at a point in the pipeline defined by the application.