From 6dd2b09df6053ef80327cbf5a2c335deed20714c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 5 Oct 2026 11:52:33 -0700 Subject: [PATCH] case 4670 miniprofiler removal entirely keywords profile profiler mini metrics this is the commit for ayanova 8 duplicating this --- server/Controllers/ServerMetricsController.cs | 2 +- server/Startup.cs | 76 +------------------ server/sockeye.csproj | 2 - 3 files changed, 3 insertions(+), 77 deletions(-) diff --git a/server/Controllers/ServerMetricsController.cs b/server/Controllers/ServerMetricsController.cs index fbd82e8..abed455 100644 --- a/server/Controllers/ServerMetricsController.cs +++ b/server/Controllers/ServerMetricsController.cs @@ -15,7 +15,7 @@ using Newtonsoft.Json.Linq; using Sockeye.Models; using Sockeye.Api.ControllerHelpers; using Sockeye.Biz; -//using StackExchange.Profiling; + namespace Sockeye.Api.Controllers { diff --git a/server/Startup.cs b/server/Startup.cs index 1b343bc..4f46628 100644 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -20,7 +20,6 @@ using Sockeye.Util; using Sockeye.Generator; using Sockeye.Biz; using NLog.Extensions.Logging; -using StackExchange.Profiling; using Asp.Versioning.ApiExplorer; using Asp.Versioning; @@ -57,24 +56,6 @@ namespace Sockeye _newLog.LogDebug("Health"); services.AddHealthChecks().AddDbContextCheck(); ; - _newLog.LogDebug("Profiler"); - //https://dotnetthoughts.net/using-miniprofiler-in-aspnetcore-webapi/ - services.AddMemoryCache(); - services.AddMiniProfiler(options => - { - options.RouteBasePath = "/profiler"; - //in testing only ignorepaths was reliable and worked and docs say it prevents any profiling at all - options.IgnorePath("/auth").IgnorePath("/user").IgnorePath("/docs").IgnorePath("/cust").IgnorePath("/notify/hello").IgnorePath("/notify/new-count"); - options.ResultsAuthorize = request => - { - if (request.HttpContext.Items["AY_PROFILER_ALLOWED"] != null) - return true; - return false; - }; - - }).AddEntityFramework(); - - //Server state service for shutting people out of api _newLog.LogDebug("ServerState service"); services.AddSingleton(new Sockeye.Api.ControllerHelpers.ApiServerState()); @@ -416,56 +397,7 @@ namespace Sockeye { if (!context.User.Identity.IsAuthenticated) { - #region Profiler workaround - //Is this a profiler route? If so we're going to use the dl token to authorize - if (context.Request.Path.Value.StartsWith("/profiler/results")) - { - //someone is requesting the profiler - //check for a dl token "t" and rehydrate user if found - //Note that the profiler UI triggers it's own requests to to get the token - //we need to check the referer which was the first page of profile - - string token = string.Empty; - //is the token in the request? - if (context.Request.Query.ContainsKey("t")) - { - token = context.Request.Query["t"].ToString(); - } - else if (context.Request.Headers["Referer"].Count > 0) - {//Maybe it's in the referer - //try to split it on the ? - string[] stuff = context.Request.Headers["Referer"].ToString().Split('?'); - if (stuff.Count() > 1) - { - var q = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(stuff[1]); - if (q.ContainsKey("t")) - { - token = q["t"].ToString(); - } - } - } - - if (!string.IsNullOrWhiteSpace(token)) - { - using (AyContext ct = ServiceProviderProvider.DBContext) - { - var u = ct.User.AsNoTracking().SingleOrDefault(z => z.DlKey == token.ToString() && z.Active == true); - if (u != null) - { - //this is necessary because they might have an expired JWT but this would just keep on working without a date check - //the default is the same timespan as the jwt so it's all good - var utcNow = new DateTimeOffset(DateTime.Now.ToUniversalTime(), TimeSpan.Zero); - if (u.DlKeyExpire > utcNow.DateTime) - { - if (Sockeye.Api.ControllerHelpers.Authorized.HasReadFullRole(u.Roles, SockType.ServerMetrics)) - context.Request.HttpContext.Items["AY_PROFILER_ALLOWED"] = true; - } - } - } - } - } - #endregion profiler workaround - + context.Request.HttpContext.Items["AY_ROLES"] = 0; await next.Invoke(); } @@ -551,11 +483,7 @@ namespace Sockeye #endregion - _newLog.LogDebug("Profiler"); - app.UseMiniProfiler(); - - - + _newLog.LogDebug("Endpoints pipeline"); app.UseEndpoints(endpoints => { diff --git a/server/sockeye.csproj b/server/sockeye.csproj index 845ed95..23095f8 100644 --- a/server/sockeye.csproj +++ b/server/sockeye.csproj @@ -34,8 +34,6 @@ all - -