Class HttpLastModifiedHeaderOptions
- Namespace
- Cuemon.AspNetCore.Mvc.Filters.Cacheable
- Assembly
- Cuemon.AspNetCore.Mvc.dll
Specifies options that is related to the HttpLastModifiedHeaderFilter.
public class HttpLastModifiedHeaderOptions : IParameterObject
- Inheritance
-
HttpLastModifiedHeaderOptions
- Implements
Examples
The following example applies the default to a timestamped response model.
using System;
using Cuemon.AspNetCore.Mvc.Filters.Cacheable;
using Cuemon.Data.Integrity;
using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers;
namespace MyApp.Examples;
public static class HttpLastModifiedHeaderOptionsExample
{
public static void Demonstrate()
{
var options = new HttpLastModifiedHeaderOptions();
var context = new DefaultHttpContext();
context.Request.Method = HttpMethods.Get;
var timestamp = new SampleEntityDataTimestamp(
DateTime.Parse("2024-01-01T00:00:00Z"),
DateTime.Parse("2024-01-02T00:00:00Z"));
options.LastModifiedProvider(timestamp, context);
Console.WriteLine(options.HasLastModifiedProvider);
Console.WriteLine(context.Response.Headers[HeaderNames.LastModified].ToString());
}
private sealed class SampleEntityDataTimestamp : IEntityDataTimestamp
{
public SampleEntityDataTimestamp(DateTime created, DateTime? modified)
{
Created = created;
Modified = modified;
}
public DateTime Created { get; }
public DateTime? Modified { get; }
}
}
Constructors
HttpLastModifiedHeaderOptions()
Initializes a new instance of the HttpLastModifiedHeaderOptions class.
public HttpLastModifiedHeaderOptions()
Remarks
The following table shows the initial property values for an instance of <xref href="Cuemon.AspNetCore.Mvc.Filters.Cacheable.HttpEntityTagHeaderOptions" data-throw-if-not-resolved="false"></xref>.
<table><thead><tr><th class="term">Property</th><th class="description">Initial Value</th></tr></thead><tbody><tr><td class="term"><xref href="Cuemon.AspNetCore.Mvc.Filters.Cacheable.HttpLastModifiedHeaderOptions.LastModifiedProvider" data-throw-if-not-resolved="false"></xref></td><td class="description"><pre><code class="lang-csharp">(timestamp, context) =>
{ Decorator.Enclose(context.Response).TryAddOrUpdateLastModifiedHeader(context.Request, timestamp.Modified ?? timestamp.Created); };
Properties
HasLastModifiedProvider
Gets a value indicating whether this instance has an LastModifiedProvider.
public bool HasLastModifiedProvider { get; }
Property Value
- bool
trueif this instance has an LastModifiedProvider; otherwise,false.
LastModifiedProvider
Gets or sets the delegate that is invoked when a result of a ResultExecutingContext is an ObjectResult and the value is an IEntityDataTimestamp implementation.
public Action<IEntityDataTimestamp, HttpContext> LastModifiedProvider { get; set; }
Property Value
- Action<IEntityDataTimestamp, HttpContext>
The delegate that provides an HTTP Last-Modified header.