In this recipe, we will learn how to transform an ASP.NET HTTP handler to ASP.NET Core middleware.
Before anything, let's recap what an HTTP handler is. An HTTP handler handles an incoming request from the ASP.NET/IIS pipeline and generates a response for a given extension file (.aspx
, .html
, .jpg
, and so on.) For ASP.NET MVC, we used a specific handler named MVCHandler
, which ensures that an action
method exists in a controller for the specified route in the request URL.
We create an empty ASP.NET Core web application with Visual Studio and .NET Core or .NET Framework.
We'll create a new project and write our first middleware. We can observe the execution mechanism of middleware with this project.
- First, let's watch the anatomy of an HTTP handler:
public class MyHttpHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response...