且构网

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

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

更新时间:2023-02-16 22:15:31

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.