Merge branch 'netcore/dev' into netcore/members-userstore

This commit is contained in:
Emma Garland
2021-02-09 13:22:40 +00:00
220 changed files with 2869 additions and 6196 deletions

View File

@@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Events;
using Umbraco.Core.Hosting;
using Umbraco.Core.Logging;
using Umbraco.Extensions;
using Umbraco.Web.Common.Profiler;
@@ -36,6 +37,7 @@ namespace Umbraco.Web.Common.Middleware
private readonly IBackOfficeSecurityFactory _backofficeSecurityFactory;
private readonly PublishedSnapshotServiceEventHandler _publishedSnapshotServiceEventHandler;
private readonly IEventAggregator _eventAggregator;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly WebProfiler _profiler;
private static bool s_cacheInitialized = false;
private static bool s_cacheInitializedFlag = false;
@@ -51,7 +53,8 @@ namespace Umbraco.Web.Common.Middleware
IBackOfficeSecurityFactory backofficeSecurityFactory,
PublishedSnapshotServiceEventHandler publishedSnapshotServiceEventHandler,
IEventAggregator eventAggregator,
IProfiler profiler)
IProfiler profiler,
IHostingEnvironment hostingEnvironment)
{
_logger = logger;
_umbracoContextFactory = umbracoContextFactory;
@@ -59,6 +62,7 @@ namespace Umbraco.Web.Common.Middleware
_backofficeSecurityFactory = backofficeSecurityFactory;
_publishedSnapshotServiceEventHandler = publishedSnapshotServiceEventHandler;
_eventAggregator = eventAggregator;
_hostingEnvironment = hostingEnvironment;
_profiler = profiler as WebProfiler; // Ignore if not a WebProfiler
}
@@ -81,6 +85,10 @@ namespace Umbraco.Web.Common.Middleware
_backofficeSecurityFactory.EnsureBackOfficeSecurity(); // Needs to be before UmbracoContext, TODO: Why?
UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();
Uri currentApplicationUrl = GetApplicationUrlFromCurrentRequest(context.Request);
_hostingEnvironment.EnsureApplicationMainUrl(currentApplicationUrl);
bool isFrontEndRequest = umbracoContextReference.UmbracoContext.IsFrontEndUmbracoRequest();
var pathAndQuery = context.Request.GetEncodedPathAndQuery();
@@ -95,7 +103,7 @@ namespace Umbraco.Web.Common.Middleware
try
{
await _eventAggregator.PublishAsync(new UmbracoRequestBegin(context));
await _eventAggregator.PublishAsync(new UmbracoRequestBegin(umbracoContextReference.UmbracoContext));
}
catch (Exception ex)
{
@@ -111,7 +119,7 @@ namespace Umbraco.Web.Common.Middleware
}
finally
{
await _eventAggregator.PublishAsync(new UmbracoRequestEnd(context));
await _eventAggregator.PublishAsync(new UmbracoRequestEnd(umbracoContextReference.UmbracoContext));
}
}
}
@@ -119,7 +127,7 @@ namespace Umbraco.Web.Common.Middleware
{
if (isFrontEndRequest)
{
LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId, _requestCache);
LogHttpRequest.TryGetCurrentHttpRequestId(out Guid httpRequestId, _requestCache);
_logger.LogTrace("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, pathAndQuery, DateTime.Now.Subtract(umbracoContextReference.UmbracoContext.ObjectCreated).TotalMilliseconds);
}
@@ -138,6 +146,18 @@ namespace Umbraco.Web.Common.Middleware
_profiler?.UmbracoApplicationEndRequest(context);
}
private Uri GetApplicationUrlFromCurrentRequest(HttpRequest request)
{
// We only consider GET and POST.
// Especially the DEBUG sent when debugging the application is annoying because it uses http, even when the https is available.
if (request.Method == "GET" || request.Method == "POST")
{
return new Uri($"{request.Scheme}://{request.Host}{request.PathBase}", UriKind.Absolute);
}
return null;
}
/// <summary>
/// Any object that is in the HttpContext.Items collection that is IDisposable will get disposed on the end of the request
/// </summary>