case 4670 miniprofiler removal entirely keywords profile profiler mini metrics this is the commit for ayanova 8 duplicating this
This commit is contained in:
@@ -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<AyContext>(); ;
|
||||
|
||||
_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 =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user