Miniprofiler Asp.Net核心请求和控制器之间的延迟

时间:2018-07-12 13:47:45

标签: asp.net-core-mvc mvc-mini-profiler

当我分析请求时,我会在Miniprofoler日志中看到下一个数据:

  MiniProfiler = ms
> Request = 285,6ms
>> Controller: Image.GetBanner = 2,3ms

为什么请求和控制器记录之间的差异如此之大? 这一次Asp.Net Core会做什么?

我的代码:

Startup.cs

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {  
    ...    
    app.UseMiddleware(typeof(RequestResponseLoggingMiddleware)); 
    app.UseMvc(routes =>
       {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
       });

    app.UseSwagger();
    app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/webshop/swagger/v1/swagger.json", "Contacts API");
            c.InjectOnCompleteJavaScript("/webshop/js/SwaggerUiCustomization.js");
        });
    }

RequestResponseLoggingMiddleware.cs

   public class RequestResponseLoggingMiddleware
    {
        private readonly RequestDelegate _next;

        public RequestResponseLoggingMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context)
        {
            using (MiniProfiler.Current.Step("Request"))
            {
                await _next(context);
            }
        }
    }

0 个答案:

没有答案