Skip to content

Custom Vary by Header Caching

Trevor Fayas edited this page Jan 1, 2022 · 2 revisions

In non Core MVC, you were allowed to create custom Vary-By parameters for the Output Cache.

.Net Core MVC does not have this feature, instead, it offers vary-by custom string, header, model, user, and some others.

Using the vary-by custom string 'works', you can create an Interface to inject and then call a method to get your vary-by-text, however another way of handling this is to add Middleware to inject custom headers and vary by those.

That's the route we have taken with our clients, and have provided that CustomVaryByMiddleware in the Baseline, so you can use it where needed.

Clone this wiki locally