Files
Umbraco-CMS/src/Umbraco.Web.Common/Profiler/WebProfilerHtml.cs
Nikolaj Geisle c576bbea03 v10: Fix build warnings in Web.Common (#12349)
* Run code cleanup

* Run dotnet format

* Start manual cleanup in Web.Common

* Finish up manual cleanup

* Fix tests

* Fix up InMemoryModelFactory.cs

* Inject proper macroRenderer

* Update src/Umbraco.Web.Common/Filters/JsonDateTimeFormatAttribute.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update src/Umbraco.Web.Common/Filters/ValidateUmbracoFormRouteStringAttribute.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix based on review

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
2022-05-09 09:39:46 +02:00

50 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Http;
using StackExchange.Profiling;
using StackExchange.Profiling.Internal;
using Umbraco.Cms.Core.Logging;
namespace Umbraco.Cms.Web.Common.Profiler;
public class WebProfilerHtml : IProfilerHtml
{
private readonly IHttpContextAccessor _httpContextAccessor;
public WebProfilerHtml(IHttpContextAccessor httpContextAccessor) =>
// create our own provider, which can provide a profiler even during boot
_httpContextAccessor = httpContextAccessor;
/// <inheritdoc />
/// <remarks>
/// Normally we would call MiniProfiler.Current.RenderIncludes(...), but because the requeststate is not set, this
/// method does not work.
/// We fake the requestIds from the RequestState here.
/// </remarks>
public string Render()
{
MiniProfiler? profiler = MiniProfiler.Current;
if (profiler == null)
{
return string.Empty;
}
HttpContext? context = _httpContextAccessor.HttpContext;
var path = (profiler.Options as MiniProfilerOptions)?.RouteBasePath.Value.EnsureTrailingSlash();
var result = StackExchange.Profiling.Internal.Render.Includes(
profiler,
context is not null ? context.Request.PathBase + path : null,
true,
new List<Guid> { profiler.Id },
RenderPosition.Right,
profiler.Options.PopupShowTrivial,
profiler.Options.PopupShowTimeWithChildren,
profiler.Options.PopupMaxTracesToShow,
profiler.Options.ShowControls,
profiler.Options.PopupStartHidden);
return result;
}
}