From 50f4d7abdefae6fb4fdc1101fb25ed17e6455bd4 Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 12 Oct 2020 13:32:25 +0200 Subject: [PATCH 1/8] Migrate UmbracoUserTimeoutFilterAttribute --- .../UmbracoAuthorizedApiController.cs | 2 +- .../UmbracoUserTimeoutFilterAttribute.cs | 39 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 - .../UmbracoUserTimeoutFilterAttribute.cs | 36 ----------------- .../WebApi/UmbracoAuthorizedApiController.cs | 2 +- 5 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs delete mode 100644 src/Umbraco.Web/WebApi/Filters/UmbracoUserTimeoutFilterAttribute.cs diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index 85c92d1139..df7c5a0c31 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -14,7 +14,7 @@ namespace Umbraco.Web.BackOffice.Controllers /// before their timeout expires. /// [IsBackOffice] - //[UmbracoUserTimeoutFilter] //TODO reintroduce + [UmbracoUserTimeoutFilter] [UmbracoAuthorize] [DisableBrowserCache] [UmbracoWebApiRequireHttps] diff --git a/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs new file mode 100644 index 0000000000..afe5e344c5 --- /dev/null +++ b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs @@ -0,0 +1,39 @@ +using System.Globalization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Umbraco.Extensions; + +namespace Umbraco.Web.Common.Filters +{ + /// + /// This will check if the request is authenticated and if there's an auth ticket present we will + /// add a custom header to the response indicating how many seconds are remaining for the current + /// user's session. This allows us to keep track of a user's session effectively in the back office. + /// + public class UmbracoUserTimeoutFilterAttribute : TypeFilterAttribute + { + public UmbracoUserTimeoutFilterAttribute() : base(typeof(UmbracoUserTimeoutFilter)) + { + } + + private class UmbracoUserTimeoutFilter : IActionFilter + { + + public void OnActionExecuted(ActionExecutedContext context) + { + //this can occur if an error has already occurred. + if (context.HttpContext.Response is null) return; + + // Using the new way to GetRemainingAuthSeconds, which does not require you to get the ticket from the request + var remainingSeconds = context.HttpContext.User.GetRemainingAuthSeconds(); + + context.HttpContext.Response.Headers.Add("X-Umb-User-Seconds", remainingSeconds.ToString(CultureInfo.InvariantCulture)); + } + + public void OnActionExecuting(ActionExecutingContext context) + { + // Noop + } + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 7b224c49b5..5f934c2359 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -372,7 +372,6 @@ - diff --git a/src/Umbraco.Web/WebApi/Filters/UmbracoUserTimeoutFilterAttribute.cs b/src/Umbraco.Web/WebApi/Filters/UmbracoUserTimeoutFilterAttribute.cs deleted file mode 100644 index 4221817a17..0000000000 --- a/src/Umbraco.Web/WebApi/Filters/UmbracoUserTimeoutFilterAttribute.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Globalization; -using System.Web.Http.Filters; -using Umbraco.Core.Security; -using Umbraco.Web.Security; - -namespace Umbraco.Web.WebApi.Filters -{ - /// - /// This will check if the request is authenticated and if there's an auth ticket present we will - /// add a custom header to the response indicating how many seconds are remaining for the current - /// user's session. This allows us to keep track of a user's session effectively in the back office. - /// - public sealed class UmbracoUserTimeoutFilterAttribute : ActionFilterAttribute - { - public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) - { - base.OnActionExecuted(actionExecutedContext); - - //this can occur if an error has already occurred. - if (actionExecutedContext.Response == null) return; - - var httpContextAttempt = actionExecutedContext.Request.TryGetHttpContext(); - if (httpContextAttempt.Success) - { - - var ticket = httpContextAttempt.Result.GetUmbracoAuthTicket(); - if (ticket?.Properties.ExpiresUtc != null && ticket.Properties.ExpiresUtc.Value < DateTimeOffset.UtcNow) - { - var remainingSeconds = httpContextAttempt.Result.GetRemainingAuthSeconds(); - actionExecutedContext.Response.Headers.Add("X-Umb-User-Seconds", remainingSeconds.ToString(CultureInfo.InvariantCulture)); - } - } - } - } -} diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 7858d6955a..2851d5e24f 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.WebApi /// before their timeout expires. /// [IsBackOffice] - [UmbracoUserTimeoutFilter] + // [UmbracoUserTimeoutFilter] has been migrated to netcore [UmbracoAuthorize] [DisableBrowserCache] // [UmbracoWebApiRequireHttps] From e44dae2fcbbc6207b680446c30580b138b7b7820 Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 12 Oct 2020 15:27:07 +0200 Subject: [PATCH 2/8] Add first swing at UnhandledExceptionLoggerMiddleware --- .../BackOfficeApplicationBuilderExtensions.cs | 2 + .../Runtime/BackOfficeComposer.cs | 1 + .../UnhandledExceptionLoggerMiddleware.cs | 43 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs diff --git a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs index 471aed51e1..a64577887c 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs @@ -2,6 +2,7 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using SixLabors.ImageSharp.Web.DependencyInjection; +using Umbraco.Web.BackOffice; using Umbraco.Web.BackOffice.Routing; using Umbraco.Web.BackOffice.Security; @@ -46,6 +47,7 @@ namespace Umbraco.Extensions app.UseUmbracoRuntimeMinification(); app.UseMiddleware(); + app.UseMiddleware(); return app; } diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index 1ce0724aea..3edf8c4177 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -48,6 +48,7 @@ namespace Umbraco.Web.BackOffice.Runtime "~/")); composition.RegisterUnique(); + composition.RegisterUnique(); } } } diff --git a/src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs b/src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs new file mode 100644 index 0000000000..d131b9cadd --- /dev/null +++ b/src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs @@ -0,0 +1,43 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; +using Microsoft.Extensions.Logging; +using Umbraco.Core; + +namespace Umbraco.Web.BackOffice +{ + public class UnhandledExceptionLoggerMiddleware : IMiddleware + { + private readonly ILogger _logger; + + public UnhandledExceptionLoggerMiddleware(ILogger logger) + { + _logger = logger; + } + + public async Task InvokeAsync(HttpContext context, RequestDelegate next) + { + var requestUri = new Uri(context.Request.GetEncodedUrl(), UriKind.RelativeOrAbsolute); + // If it's a client side request just call next and don't try to log anything + if (requestUri.IsClientSideRequest()) + { + await next(context); + } + else + { + // We call the next middleware, and catch any errors that occurs in the rest of the pipeline + try + { + await next(context); + } + catch (Exception e) + { + _logger.LogError(e, "Unhandled controller exception occurred for request '{RequestUrl}'", requestUri.AbsoluteUri); + // throw the error again, just in case it gets handled (which is shouldn't) + throw; + } + } + } + } +} From 96f6f9cedef11dde8608c0f415601e4246859f2c Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 08:46:52 +0200 Subject: [PATCH 3/8] Fix logging for now The service provider is built before logging is registered as a service, meaning that the loggerFactory was empty, rebuilding fixes the issue for now, but it's not very pretty, would be better if we could move logger registration out of CreateCompositionRoot --- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index 1b3cde509a..adae78bd74 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -275,7 +275,7 @@ namespace Umbraco.Extensions loggingConfiguration, configuration, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); - var loggerFactory = serviceProvider.GetService(); + var loggerFactory = services.BuildServiceProvider().GetService(); var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(loggerFactory, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); From 5d1383cf2c39b7d0253338a7c145bd725358a8c3 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 09:39:31 +0200 Subject: [PATCH 4/8] Use MiddlewareFilter for UnhandledExceptionLoggerFilter --- .../Controllers/UmbracoAuthorizedApiController.cs | 5 +++-- .../BackOfficeApplicationBuilderExtensions.cs | 1 - .../Filters/UnhandledExceptionLoggerFilter.cs | 13 +++++++++++++ .../UnhandledExceptionLoggerMiddleware.cs | 2 +- .../Runtime/BackOfficeComposer.cs | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs rename src/Umbraco.Web.BackOffice/{ => Filters}/UnhandledExceptionLoggerMiddleware.cs (97%) diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index df7c5a0c31..bf86410ae3 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -1,4 +1,5 @@ -using Umbraco.Web.BackOffice.Filters; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Common.Attributes; using Umbraco.Web.Common.Controllers; using Umbraco.Web.Common.Filters; @@ -19,7 +20,7 @@ namespace Umbraco.Web.BackOffice.Controllers [DisableBrowserCache] [UmbracoWebApiRequireHttps] [CheckIfUserTicketDataIsStale] - //[UnhandedExceptionLoggerConfiguration] //TODO reintroduce + [MiddlewareFilter(typeof(UnhandledExceptionLoggerFilter))] //[EnableDetailedErrors] //TODO reintroduce public abstract class UmbracoAuthorizedApiController : UmbracoApiController { diff --git a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs index a64577887c..9392fd0987 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs @@ -47,7 +47,6 @@ namespace Umbraco.Extensions app.UseUmbracoRuntimeMinification(); app.UseMiddleware(); - app.UseMiddleware(); return app; } diff --git a/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs new file mode 100644 index 0000000000..fcc12f2388 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Builder; + + +namespace Umbraco.Web.BackOffice.Filters +{ + public class UnhandledExceptionLoggerFilter + { + public void Configure(IApplicationBuilder applicationBuilder) + { + applicationBuilder.UseMiddleware(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs similarity index 97% rename from src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs rename to src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs index d131b9cadd..50a28be24b 100644 --- a/src/Umbraco.Web.BackOffice/UnhandledExceptionLoggerMiddleware.cs +++ b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Http.Extensions; using Microsoft.Extensions.Logging; using Umbraco.Core; -namespace Umbraco.Web.BackOffice +namespace Umbraco.Web.BackOffice.Filters { public class UnhandledExceptionLoggerMiddleware : IMiddleware { diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index 3edf8c4177..005a0db36e 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -7,6 +7,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Extensions; using Umbraco.Web.BackOffice.Controllers; +using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.BackOffice.Routing; using Umbraco.Web.BackOffice.Security; using Umbraco.Web.BackOffice.Services; From 9e5fda6c42aa2e3d12e27bff3c17ddbd811d8da7 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 13:05:08 +0200 Subject: [PATCH 5/8] Remove old UnhandedExceptionLoggerConfigurationAttribute and UnhandledExceptionLogger --- src/Umbraco.Web/Umbraco.Web.csproj | 2 -- .../WebApi/UmbracoAuthorizedApiController.cs | 2 +- ...edExceptionLoggerConfigurationAttribute.cs | 29 --------------- .../WebApi/UnhandledExceptionLogger.cs | 36 ------------------- 4 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs delete mode 100644 src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 5f934c2359..5f6ce7fc84 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -237,8 +237,6 @@ - - diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index 2851d5e24f..993fd36bc2 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.WebApi [DisableBrowserCache] // [UmbracoWebApiRequireHttps] // [CheckIfUserTicketDataIsStale] - [UnhandedExceptionLoggerConfiguration] + // [UnhandedExceptionLoggerConfiguration] [EnableDetailedErrors] public abstract class UmbracoAuthorizedApiController : UmbracoApiController { diff --git a/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs b/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs deleted file mode 100644 index 6dc1a49eb1..0000000000 --- a/src/Umbraco.Web/WebApi/UnhandedExceptionLoggerConfigurationAttribute.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using System.Web.Http.Controllers; -using System.Web.Http.ExceptionHandling; -using System.Web.Http.Filters; -using Umbraco.Core; -using Umbraco.Core.Logging; - -namespace Umbraco.Web.WebApi -{ - /// - /// Adds our unhandled exception logger to the controller's services - /// - /// - /// Important to note that the will only be called if the controller has an ExceptionFilter applied - /// to it, so to kill two birds with one stone, this class inherits from ExceptionFilterAttribute purely to force webapi to use the - /// IExceptionLogger (strange) - /// - public class UnhandedExceptionLoggerConfigurationAttribute : ExceptionFilterAttribute, IControllerConfiguration - { - public virtual void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) - { - controllerSettings.Services.Add(typeof(IExceptionLogger), new UnhandledExceptionLogger()); - } - - } -} diff --git a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs b/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs deleted file mode 100644 index 903e333846..0000000000 --- a/src/Umbraco.Web/WebApi/UnhandledExceptionLogger.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Web.Http.ExceptionHandling; -using Umbraco.Web.Composing; -using Microsoft.Extensions.Logging; - -namespace Umbraco.Web.WebApi -{ - /// - /// Used to log unhandled exceptions in webapi controllers - /// - public class UnhandledExceptionLogger : ExceptionLogger - { - private readonly ILogger _logger; - - public UnhandledExceptionLogger() - : this(Current.Logger) - { - } - - public UnhandledExceptionLogger(ILogger logger) - { - _logger = logger; - } - - public override void Log(ExceptionLoggerContext context) - { - if (context != null && context.Exception != null) - { - var requestUrl = context.ExceptionContext?.ControllerContext?.Request?.RequestUri?.AbsoluteUri; - var controllerType = context.ExceptionContext?.ActionContext?.ControllerContext?.Controller?.GetType(); - - _logger.LogError(context.Exception, "Unhandled controller exception occurred for request '{RequestUrl}'", requestUrl); - } - } - - } -} From 87a8bfec8a3148d4c464b476dabc6ad8e68e9f83 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 13:51:17 +0200 Subject: [PATCH 6/8] Remove TODO in umbracoAuthorizedApiController This requires a change in JsonExceptionFilterAttribute not an actual filter --- .../Controllers/UmbracoAuthorizedApiController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs index bf86410ae3..c232401b78 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/UmbracoAuthorizedApiController.cs @@ -21,7 +21,6 @@ namespace Umbraco.Web.BackOffice.Controllers [UmbracoWebApiRequireHttps] [CheckIfUserTicketDataIsStale] [MiddlewareFilter(typeof(UnhandledExceptionLoggerFilter))] - //[EnableDetailedErrors] //TODO reintroduce public abstract class UmbracoAuthorizedApiController : UmbracoApiController { From d38befa9c020a311b163f0447f7c6e4605afd2e8 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 14:26:29 +0200 Subject: [PATCH 7/8] Minor cleaning --- .../Extensions/BackOfficeApplicationBuilderExtensions.cs | 1 - .../Filters/UnhandledExceptionLoggerFilter.cs | 5 +++++ .../Filters/UnhandledExceptionLoggerMiddleware.cs | 7 +++++-- .../Filters/UmbracoUserTimeoutFilterAttribute.cs | 3 --- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs index 9392fd0987..471aed51e1 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs @@ -2,7 +2,6 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using SixLabors.ImageSharp.Web.DependencyInjection; -using Umbraco.Web.BackOffice; using Umbraco.Web.BackOffice.Routing; using Umbraco.Web.BackOffice.Security; diff --git a/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs index fcc12f2388..ebea90249c 100644 --- a/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs +++ b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerFilter.cs @@ -3,6 +3,11 @@ using Microsoft.AspNetCore.Builder; namespace Umbraco.Web.BackOffice.Filters { + /// + /// Applies the UnhandledExceptionLoggerMiddleware to a specific controller + /// when used with this attribute [MiddlewareFilter(typeof(UnhandledExceptionLoggerFilter))] + /// The middleware will run in the filter pipeline, at the same stage as resource filters + /// public class UnhandledExceptionLoggerFilter { public void Configure(IApplicationBuilder applicationBuilder) diff --git a/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs index 50a28be24b..db6162afa8 100644 --- a/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs +++ b/src/Umbraco.Web.BackOffice/Filters/UnhandledExceptionLoggerMiddleware.cs @@ -7,6 +7,9 @@ using Umbraco.Core; namespace Umbraco.Web.BackOffice.Filters { + /// + /// Logs any unhandled exception. + /// public class UnhandledExceptionLoggerMiddleware : IMiddleware { private readonly ILogger _logger; @@ -26,7 +29,7 @@ namespace Umbraco.Web.BackOffice.Filters } else { - // We call the next middleware, and catch any errors that occurs in the rest of the pipeline + // Call the next middleware, and catch any errors that occurs in the rest of the pipeline try { await next(context); @@ -34,7 +37,7 @@ namespace Umbraco.Web.BackOffice.Filters catch (Exception e) { _logger.LogError(e, "Unhandled controller exception occurred for request '{RequestUrl}'", requestUri.AbsoluteUri); - // throw the error again, just in case it gets handled (which is shouldn't) + // Throw the error again, just in case it gets handled throw; } } diff --git a/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs index afe5e344c5..a5bf24335b 100644 --- a/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs @@ -18,15 +18,12 @@ namespace Umbraco.Web.Common.Filters private class UmbracoUserTimeoutFilter : IActionFilter { - public void OnActionExecuted(ActionExecutedContext context) { //this can occur if an error has already occurred. if (context.HttpContext.Response is null) return; - // Using the new way to GetRemainingAuthSeconds, which does not require you to get the ticket from the request var remainingSeconds = context.HttpContext.User.GetRemainingAuthSeconds(); - context.HttpContext.Response.Headers.Add("X-Umb-User-Seconds", remainingSeconds.ToString(CultureInfo.InvariantCulture)); } From 80d3b64a5f047161e44b2a31687d679e9e321409 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 13 Oct 2020 14:34:10 +0200 Subject: [PATCH 8/8] Change summary of UmbracoUserTimeoutFilterAttribute to more accurately describe what it does now --- .../Filters/UmbracoUserTimeoutFilterAttribute.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs index a5bf24335b..2c11b06839 100644 --- a/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs +++ b/src/Umbraco.Web.Common/Filters/UmbracoUserTimeoutFilterAttribute.cs @@ -6,8 +6,8 @@ using Umbraco.Extensions; namespace Umbraco.Web.Common.Filters { /// - /// This will check if the request is authenticated and if there's an auth ticket present we will - /// add a custom header to the response indicating how many seconds are remaining for the current + /// This will check if the user making the request is authenticated and if there's an auth ticket tied to the user + /// we will add a custom header to the response indicating how many seconds are remaining for the /// user's session. This allows us to keep track of a user's session effectively in the back office. /// public class UmbracoUserTimeoutFilterAttribute : TypeFilterAttribute