我只找到了 这篇指南,介绍如何使用 MiniProfiler 在 ASP.NET Web API 和 Swagger UI 中运行,但是我没有找到任何关于如何让 ASP.NET Core Web API 与 MiniProfiler 配合显示结果在 Swagger UI 中的指南。
我只找到了 这篇指南,介绍如何使用 MiniProfiler 在 ASP.NET Web API 和 Swagger UI 中运行,但是我没有找到任何关于如何让 ASP.NET Core Web API 与 MiniProfiler 配合显示结果在 Swagger UI 中的指南。
index.html
文件。在创建自定义HTML文件后,将以下行添加到其中:<script async="async" id="mini-profiler" src="/profiler/includes.js?v=4.0.0.0" data-version="4.0.0.0" data-path="/profiler/" data-current-id="865f1487-f416-4d39-87fe-723e34847577" data-ids="" data-position="left" data-authorized="true" data-max-traces="15" data-toggle-shortcut="Alt+P" data-trivial-milliseconds="2.0" data-ignored-duplicate-execute-types="Open,OpenAsync,Close,CloseAsync"></script>
基本上,以上脚本是MiniProfiler.Current.RenderIncludes()
方法的输出。
以下是ConfigureServices
和Configure
方法,以查看Swagger和Miniprofiler如何配置
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// Register the Swagger generator, defining one or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
services.AddMiniProfiler(options =>
options.RouteBasePath = "/profiler"
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMiniProfiler();
}
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.IndexStream = () => GetType().GetTypeInfo().Assembly.GetManifestResourceStream("SOMpSwaggerNetCore.SwaggerIndex.html");
});
app.UseMvc();
}
RenderIncludes()
方法的输出可能会改变,这个解决方案将停止工作。 - Alexey Andrushkevich/mini-profiler-resources/results
这个地址上收到404的错误,所以无法获取查询的性能分析结果(这种情况偶尔发生,没有规律可循),但是再试一次就没问题了。这是MiniProfiler的bug吗? - Vadim Ovchinnikov