C# 将MiniProfiler连接到ASP.NET核心Web API Swagger
我发现只描述了如何使MiniProfiler与ASP.NET Web API和Swagger UI协同工作,但我没有找到任何手册来描述如何使ASP.NET核心Web API与MiniProfiler协同工作,以在Swagger UI中显示结果。您所需要的只是定制SwaggerC# 将MiniProfiler连接到ASP.NET核心Web API Swagger,c#,asp.net-core,swagger-ui,asp.net-core-webapi,mvc-mini-profiler,C#,Asp.net Core,Swagger Ui,Asp.net Core Webapi,Mvc Mini Profiler,我发现只描述了如何使MiniProfiler与ASP.NET Web API和Swagger UI协同工作,但我没有找到任何手册来描述如何使ASP.NET核心Web API与MiniProfiler协同工作,以在Swagger UI中显示结果。您所需要的只是定制Swaggerindex.html文件,就像在。创建自定义HTML文件后,在其中添加以下行: 基本上,上面的脚本是MiniProfiler.Current.RenderIncludes()方法的输出 下面是ConfigureServi
index.html
文件,就像在。创建自定义HTML文件后,在其中添加以下行:
基本上,上面的脚本是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();
}
好的,我已经这样做了,但是自定义HTML是一个挑战,因为我不能在那里指定razor语句来呈现MiniProfiler视图。您不需要这样做。我已经添加了确切的脚本,该脚本将被添加到HTML文件中。该解决方案并不理想,因为如果以后更新MiniProfiler版本,
RenderIncludes()的输出
方法可能会更改,此解决方案将停止工作。如果您想动态呈现MiniProfiler includes,您可以在此HTML文件中添加多一点JS代码,这基本上会向您的API发出AJAX请求,返回MiniProfiler.Current.RenderIncludes的结果。如果您没有设置路由分离路径
属性,然后使用默认路径/mini-profiler-resources/includes.js
我有时会为/mini-profiler-resources/results
获取404,因此我不会获取用于查询的探查器结果(偶尔会发生,未检测到模式),但在尝试相同的方法后就可以了。是迷你档案器的错误吗?