将MiniProfiler与.NetCore 3.1集成 [英] Integrate MiniProfiler with .NetCore 3.1

查看:735
本文介绍了将MiniProfiler与.NetCore 3.1集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要集成的MiniProfiler是WebApi或View/XX/results-index. WebApi已通过Bearer令牌进行了身份验证.我只希望Active Directory中的组用户可以看到结果,但我不明白.

I want to integrate MiniProfiler is a WebApi or View /XX/results-index. The WebApi is authenticated with Bearer Tokens. I only want Group Users in Active Directory can see the results, but I don't get it.

我在ServicesCollection中有以下代码:

I have this code in ServicesCollection:

services.AddMiniProfiler(options =>
{
   options.RouteBasePath = "/profiler";
   options.ResultsAuthorizeAsync = async request => await GetAuthorization(request);            }).AddEntityFramework();

private static async Task<bool> GetAuthorization(HttpRequest request)
{
 //   var user = request.HttpContext.User.Identity.Name; --> Is null
   return true;
}

在启动时的配置方法"中:

In Configure Method in StartUp:

app.UseSwagger().UseSwaggerUI(options =>
{
   options.SwaggerEndpoint($"/swagger/v1/swagger.json", $"{env.ApplicationName} V1");
   options.OAuthClientId("TestApiswaggerui");
   options.OAuthAppName("TestApi Swagger UI");
   options.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream(
                        "TestApi.SwaggerMiniProfiler.html");
})
.UseMiniProfiler();

我想通过一些选项查看小型探查器信息:

I want to see mini profiler information through some options:

  • http://localhost:5050/profiler/results-index->显示名为的列表方法
  • http://localhost:5050/swagger/index.html->在同一页面中显示MiniProfiler

环境:

.NET Core version: 3.1
MiniProfiler version: MiniProfiler.AspNetCore.Mvc v.4.2.1
Operative system: Windows 10

推荐答案

我只想保留从活动目录中读取该组的跟踪信息的选项:

I just want to leave the option of having the traces read for that group from the active directory:

 services.AddMiniProfiler(options =>
                    {
                        // (Optional) Path to use for profiler URLs, default is /mini-profiler-resources
                        options.RouteBasePath = "/profiler";

                        options.ColorScheme = StackExchange.Profiling.ColorScheme.Light;
                        options.PopupRenderPosition = StackExchange.Profiling.RenderPosition.BottomLeft;
                        options.PopupShowTimeWithChildren = true;
                        options.PopupShowTrivial = true;
                        options.ShouldProfile = ShowProfile;
                        options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();

                        options.ResultsAuthorize = request => request.HttpContext.User.IsInRole("S-INFORMATICA");
 })
                    .AddEntityFramework();

这篇关于将MiniProfiler与.NetCore 3.1集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆