Moved logic from all around into the repository
This commit is contained in:
@@ -20,8 +20,10 @@
|
||||
@inject IProfilerHtml profilerHtml
|
||||
@inject IIconService IconService
|
||||
@inject IBackOfficeExternalLoginProviders externalLogins
|
||||
@inject IWebProfilerService WebProfilerService
|
||||
@{
|
||||
bool.TryParse(Context.Request.Query["umbDebug"], out bool isDebug);
|
||||
var webProfilingStatus = await WebProfilerService.GetStatus();
|
||||
var isDebug = (webProfilingStatus.Success && webProfilingStatus.Result) ? true : false;
|
||||
var backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,18 +130,7 @@ public class WebProfiler : IProfiler
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (bool.TryParse(request.Query["umbDebug"], out var umbDebug))
|
||||
{
|
||||
return umbDebug;
|
||||
}
|
||||
|
||||
if (bool.TryParse(request.Headers["X-UMB-DEBUG"], out var xUmbDebug))
|
||||
{
|
||||
return xUmbDebug;
|
||||
}
|
||||
|
||||
var webProfilerService = _httpContextAccessor.HttpContext?.RequestServices?.GetService<IWebProfilerService>();
|
||||
IWebProfilerService? webProfilerService = _httpContextAccessor.HttpContext?.RequestServices?.GetService<IWebProfilerService>();
|
||||
|
||||
if (webProfilerService is not null)
|
||||
{
|
||||
|
||||
@@ -6,8 +6,11 @@ namespace Umbraco.Cms.Web.Common.Repositories;
|
||||
|
||||
internal class WebProfilerRepository : IWebProfilerRepository
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private const string CookieName = "UMB-DEBUG";
|
||||
private const string HeaderName = "X-UMB-DEBUG";
|
||||
private const string QueryName = "umbDebug";
|
||||
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public WebProfilerRepository(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
@@ -26,5 +29,20 @@ internal class WebProfilerRepository : IWebProfilerRepository
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetStatus(int userId) => _httpContextAccessor.GetRequiredHttpContext().Request.Cookies.ContainsKey(CookieName);
|
||||
public bool GetStatus(int userId)
|
||||
{
|
||||
|
||||
var request = _httpContextAccessor.GetRequiredHttpContext().Request;
|
||||
if (bool.TryParse(request.Query[QueryName], out var umbDebug))
|
||||
{
|
||||
return umbDebug;
|
||||
}
|
||||
|
||||
if (bool.TryParse(request.Headers[HeaderName], out var xUmbDebug))
|
||||
{
|
||||
return xUmbDebug;
|
||||
}
|
||||
|
||||
return request.Cookies.ContainsKey(CookieName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Routing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Core.Web;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
@@ -134,12 +135,7 @@ _cleanedUmbracoUrl ??= _uriUtility.UriToUmbraco(OriginalRequestUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(string.IsNullOrEmpty(_httpContextAccessor.HttpContext?.GetRequestValue("umbdebug")) == false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var webProfilerStatusAttempt = _webProfilerService.GetStatus().GetAwaiter().GetResult();
|
||||
Attempt<bool, WebProfilerOperationStatus> webProfilerStatusAttempt = _webProfilerService.GetStatus().GetAwaiter().GetResult();
|
||||
|
||||
if (webProfilerStatusAttempt.Success)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user