Middleware does not have access to MVC constructs or context. ASP.NET Core 1.1 introduced middleware as MVC filters, providing access to the MVC constructs and context for middleware components.
- [Instructor] The final middleware update…in 1.1 is the ability to use middleware as MVC filters.…And the advantage here is that filters…have access to the MVC context and constructs,…and using middleware as a filter…provides the same access to the middleware.…Now, they run in the same stage as resource filters,…which is before model binding…and after the rest of the pipeline.…To do this, we create a custom class…with a Configure method, and then we add…to the controller or action the MiddlewareFilter attribute,…calling the type of this class.…
So let's look at this in code.…So here I have a custom class called MyMiddleWareItem,…and I have my Configure method…that takes an IapplicationBuilder as its only parameter.…And then you would do whatever you need to do…to create your middleware.…Now, to keep the example simple,…I'm just going to add in response compression.…So I have applicationBuilder.UseResponseCompression,…and that way I can specifically target certain areas…for compression.…
To get this sample to run,…
- Running and debugging ASP.NET Core applications
- Pros and cons of migrating existing applications to ASP.NET Core.
- Built-in dependency injection
- Environment awareness and app configuration
- Web host configuration and SSL
- View components invoked as tag helpers
- Configuration and logging
- Using Razor Pages
- Web API improvements
- Support for creating GDPR-compliant applications
Skill Level Intermediate
Entity Framework Core Essential Training: 1with Phil Japikse3h 20m Intermediate
Use the exercise files3m 37s
1. Get to Know .NET Core
2. ASP.NET Core 1.0
3. ASP.NET Core 1.1
4. ASP.NET Core 2.0
5. ASP.NET Core 2.1
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.