Skip to main content

Customising the Umbraco Pipeline

The excuse for today's post is I need somewhere to write up some findings from an Umbraco support case I've been looking into. A customer was using an external library that provided middleware that needed to be configured between UseRouting() and UseEndpoints(). Which isn't a problem if you have full control over the contents of the StartUp.cs class, but it's not so easy when Umbraco is doing some of this setup for you.

Thanks to Benjamin Carleski from the Umbraco community who figured this out and shared it in this forum conversation. Nothing is really different from his answer on setting up CORS, but in this post I can more easily and permanently share the sample code.

Assuming we have a library that requires a typical "Add..." addition in the ConfigureServices method and "Use..." in the Configure method of Startup.cs.

First we need a pipeline filter class:

Then a class responsible for inserting this filter in the pipeline:

And finally, in Startup.cs, ConfigureServices method, we can add: