In this recipe, we will learn how to transform an ASP.NET HTTP module in ASP.NET Core middleware.
Before anything, let's brush up on what an HTTP handler is. An HTTP module can add a treatment to an incoming request from the ASP.NET/IIS pipeline before it arrives at the handler, and/or add a treatment to the generated response. It can even transform or generate its own response.
We create an empty ASP.NET Core web application with Visual Studio and .NET Core or the .NET Framework.
We'll create a new HTTP module, and track the starting/ending point of the request. We will also add information to the beginning of the response and end of the response.
- First, let's see the anatomy of an HTTP module:
public class MyHttpModule : IHttpModule { public void Dispose(){} public void Init(HttpApplication context) { context.BeginRequest += (source, args) => { context.Response.Write("MyHttpModule BeginRequest"...