From the course: ASP.NET Core: Middleware

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Implement a middleware

Solution: Implement a middleware - ASP.NET Core Tutorial

From the course: ASP.NET Core: Middleware

Solution: Implement a middleware

(upbeat music) - [Instructor] Welcome back. As always, there's more than one way of doing things, so if you've come to a different solution, that is perfectly fine. Mine is just a suggestion. Usually when you have something like an A/B test, you just have different content on the server, and then the application would then either use one view or the other. That works especially well when using MVC, but of course can also be achieved with Razor Pages or in a Blazor application. I'd like to use a middleware though, and I will be using a redirect, and you'll see the effect of that. Here's how this can be achieved. All right, before we start, let me get rid of some of the middlewares we already have in there. We now need to do two things. We need to find out whether we were actually trying to retrieve that index Razor page, and if so, we might redirect to the new version so we can do the A/B test. Here's how that could look like. So we start once again with app.Use, receiving at context…

Contents