Closed KevinDockx closed 2 years ago
Hello Kevin.
I've run in to this issue using the default dotnet 6 template and I'm curious where I should place UseHttpCacheHeaders( )
?
Currently I've done the following:
app.UseHttpCacheHeaders( );
app.UseRouting( );
app.UseAuthorization( );
app.MapControllers( );
As you can see I explicitly call UseRouting
which I believe is now called in the WebApplicationBuilder
.
As per MSDN
they mention that if we need to we can call those methods which are currently called in the WebApplicationBuilder
.
@wbuck You are correct, it's now in the builder. But you can call UseRouting() to specify where in the pipeline the route matching will happen.
"When using the minimal hosting model, the endpoint routing middleware wraps the entire middleware pipeline, therefore there's no need to have explicit calls to UseRouting or UseEndpoints to register routes. UseRouting can still be used to specify where route matching happens, but UseRouting doesn't need to be explicitly called if routes should be matched at the beginning of the middleware pipeline."
As mentioned by @MJomaa, you can still call into UseRouting manually. Yet it's not strictly necessary for the cache headers middleware. I added a .NET 6 sample: https://github.com/KevinDockx/HttpCacheHeaders/tree/master/sample/Marvin.Cache.Headers.Sample.NET6 :)
Default templates will probably no longer call into UseRouting / UseEndpoints. Currently, UseCacheHeaders must be placed between these two statements. Investigate whether to / how to update documentation in accordance with default .NET 6 template. Potentially provide a sample.
Cfr:
app.MapControllers(endpoints => { // cache headers here? });