How to do it...

We'll create a new project and write our first middleware. We can observe the execution mechanism of middleware with this project.

  1. 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.Write("This page pass by MyHttpHandler <br />"); 
  } 
} 
  1. Now, let's see the Web.config configuration:
<system.webServer> 
    <handlers> 
      <add name="MyReportHandler" verb="*" path="*.report" type="MyApp.HttpHandlers.MyReportHandler" resourceType="Unspecified" /> 
    </handlers> 
</system.webServer> 

We had to specify a name, the authorized HTTP verbs for this Handler, the path, which is the named ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.