diff --git a/README.md b/README.md index 59ee455c..b51d2002 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ public void ConfigureServices(IServiceCollection services) o.IgnoredResourceExtensions = new[] { "jpg", "gif", "png", "css", "js", "ico", "swf", "woff" }; o.Logging = LoggerMode.On; o.LogWithHostname = false; + o.ActiveStatusCodes = new int[] { StatusCodes.Status404NotFound }; o.AddProvider(); }); @@ -151,6 +152,8 @@ If the `bufferSize` is set to `0`, the `threshold` value will be ignored, and ev **LogWithHostname**: Set to `true` to include hostname in the log. Useful in a multisite environment with several hostnames/domains. Default is `false` +**ActiveStatusCodes**: A integerlist with the status codes that NotFoundHandler will be active on. (Ex. ```options.ActiveStatusCodes = new int[] { StatusCodes.Status404NotFound, StatusCodes.Status410Gone };```) + ### Specifying ignored resources **IgnoredResourceExtensions** diff --git a/src/Geta.NotFoundHandler.Admin/Geta.NotFoundHandler.Admin.csproj b/src/Geta.NotFoundHandler.Admin/Geta.NotFoundHandler.Admin.csproj index 5daceb3f..b3446e9b 100644 --- a/src/Geta.NotFoundHandler.Admin/Geta.NotFoundHandler.Admin.csproj +++ b/src/Geta.NotFoundHandler.Admin/Geta.NotFoundHandler.Admin.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 true Geta.NotFoundHandler.Admin Admin UI for NotFound Handler for ASP.NET Core and EPiServer diff --git a/src/Geta.NotFoundHandler.Optimizely.Commerce/Geta.NotFoundHandler.Optimizely.Commerce.csproj b/src/Geta.NotFoundHandler.Optimizely.Commerce/Geta.NotFoundHandler.Optimizely.Commerce.csproj index fe2fb61a..c02be0a0 100644 --- a/src/Geta.NotFoundHandler.Optimizely.Commerce/Geta.NotFoundHandler.Optimizely.Commerce.csproj +++ b/src/Geta.NotFoundHandler.Optimizely.Commerce/Geta.NotFoundHandler.Optimizely.Commerce.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Geta.NotFoundHandler.Optimizely.Commerce NotFound handler Admin UI integration Optimizely Commerce Geta Digital diff --git a/src/Geta.NotFoundHandler.Optimizely/Geta.NotFoundHandler.Optimizely.csproj b/src/Geta.NotFoundHandler.Optimizely/Geta.NotFoundHandler.Optimizely.csproj index b097854f..4e040931 100644 --- a/src/Geta.NotFoundHandler.Optimizely/Geta.NotFoundHandler.Optimizely.csproj +++ b/src/Geta.NotFoundHandler.Optimizely/Geta.NotFoundHandler.Optimizely.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 true Geta.NotFoundHandler.Optimizely NotFound handler Admin UI integration Optimizely diff --git a/src/Geta.NotFoundHandler/Core/RequestHandler.cs b/src/Geta.NotFoundHandler/Core/RequestHandler.cs index fe56a23d..1ce8b66f 100644 --- a/src/Geta.NotFoundHandler/Core/RequestHandler.cs +++ b/src/Geta.NotFoundHandler/Core/RequestHandler.cs @@ -44,9 +44,9 @@ public virtual void Handle(HttpContext context) return; } - if (context.Response.StatusCode != 404) + if (_configuration.ActiveStatusCodes.Any() && !_configuration.ActiveStatusCodes.Contains(context.Response.StatusCode)) { - LogDebug("Not a 404 response.", context); + LogDebug("Not a accepted statuscode.", context); return; } diff --git a/src/Geta.NotFoundHandler/Geta.NotFoundHandler.csproj b/src/Geta.NotFoundHandler/Geta.NotFoundHandler.csproj index ace405e6..2e59c544 100644 --- a/src/Geta.NotFoundHandler/Geta.NotFoundHandler.csproj +++ b/src/Geta.NotFoundHandler/Geta.NotFoundHandler.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 Geta.NotFoundHandler NotFound Handler for ASP.NET Core Geta Digital diff --git a/src/Geta.NotFoundHandler/Infrastructure/Configuration/NotFoundHandlerOptions.cs b/src/Geta.NotFoundHandler/Infrastructure/Configuration/NotFoundHandlerOptions.cs index 28ad8c5e..6838358f 100644 --- a/src/Geta.NotFoundHandler/Infrastructure/Configuration/NotFoundHandlerOptions.cs +++ b/src/Geta.NotFoundHandler/Infrastructure/Configuration/NotFoundHandlerOptions.cs @@ -6,6 +6,7 @@ using Geta.NotFoundHandler.Core; using Geta.NotFoundHandler.Core.Suggestions; using Geta.NotFoundHandler.Core.Redirects; +using Microsoft.AspNetCore.Http; namespace Geta.NotFoundHandler.Infrastructure.Configuration { @@ -20,6 +21,7 @@ public class NotFoundHandlerOptions public bool UseInternalScheduler { get; set; } public string InternalSchedulerCronInterval { get; set; } = "0 0 * * *"; public FileNotFoundMode HandlerMode { get; set; } = FileNotFoundMode.On; + public int[] ActiveStatusCodes { get; set; } = new int[] { StatusCodes.Status404NotFound }; public TimeSpan RegexTimeout { get; set; } = TimeSpan.FromMilliseconds(100); public string[] IgnoredResourceExtensions { get; set; } = diff --git a/tests/Geta.NotFoundHandler.Optimizely.Tests/Geta.NotFoundHandler.Optimizely.Tests.csproj b/tests/Geta.NotFoundHandler.Optimizely.Tests/Geta.NotFoundHandler.Optimizely.Tests.csproj index 4e743fee..05827468 100644 --- a/tests/Geta.NotFoundHandler.Optimizely.Tests/Geta.NotFoundHandler.Optimizely.Tests.csproj +++ b/tests/Geta.NotFoundHandler.Optimizely.Tests/Geta.NotFoundHandler.Optimizely.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false diff --git a/tests/Geta.NotFoundHandler.Tests/Geta.NotFoundHandler.Tests.csproj b/tests/Geta.NotFoundHandler.Tests/Geta.NotFoundHandler.Tests.csproj index a872d0db..b48a184b 100644 --- a/tests/Geta.NotFoundHandler.Tests/Geta.NotFoundHandler.Tests.csproj +++ b/tests/Geta.NotFoundHandler.Tests/Geta.NotFoundHandler.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false