kdx-perbol
08/09/2024, 10:04 AMapp.UseStaticFiles( ... )
to customize the behavior, but I don't know where/when to put this in Program.cs
. I'm guessing .UseUmbraco()
already does this internally? I'm using the Umbraco 13 NuGet project template.kdx-perbol
08/09/2024, 10:12 AMUseUmbraco
, but I'm worried I'm changing some default behavior Umbraco relies on.D_Inventor
08/09/2024, 10:26 AM.UseStaticFiles()
, however, there is an extension point where you can modify the settings! You can implement IConfigureOptions<StaticFileOptions>
. I use this to add response cache headers to the output like this:
csharp
public class CachingStaticFileOptionsConfiguration : IConfigureOptions<StaticFileOptions>
{
public void Configure(StaticFileOptions options)
{
options.OnPrepareResponse = ctx =>
{
// exclude requests to backoffice resources,
// because they already have finetuned headers
if (IsUmbracoRequest(ctx.Context))
{
return;
}
Microsoft.AspNetCore.Http.Headers.ResponseHeaders headers = ctx.Context.Response.GetTypedHeaders();
headers.CacheControl = new CacheControlHeaderValue
{
Public = true,
MaxAge = TimeSpan.FromSeconds(Defaults.StaticAssetResponseCacheDuration),
Extensions =
{
new NameValueHeaderValue("immutable")
}
};
};
}
private static bool IsUmbracoRequest(HttpContext context)
{
return context.Request.Path.StartsWithSegments("/umbraco");
}
}
Would that work for you?D_Inventor
08/09/2024, 10:26 AMcsharp
builder.Services.ConfigureOptions<CachingStaticFileOptionsConfiguration>();
kdx-perbol
08/09/2024, 10:31 AMUseStaticFiles()
? I didn't find anything when searching.D_Inventor
08/09/2024, 10:32 AMD_Inventor
08/09/2024, 10:33 AMbielu
08/09/2024, 1:41 PMkdx-perbol
08/09/2024, 9:29 PMbielu
08/09/2024, 9:44 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by