Create custom middleware to replace HTTP response images in ASP .NET (three different solutions)



Create custom middleware to replace HTTP response images in ASP .NET (three different solutions)

Create custom middleware to replace HTTP response images in ASP .NET (three different solutions)

Authorised Territory code examples – This ASP .NET C# tutorial shows three different solutions to replace HTTP context reponse body with a new body using custom middleware.
We create a simple website that displays images of customers. Next, we create a middleware to replace those images with an anonymous image. We achieve this by replacing the reponse body. First two solutions create an inline middleware using app.Use while the last solution creates a custom middleware inside its own class. Finally, we test using Chrome browser running in incognito mode.