예제 #1
0
        //中间件入口只能叫Invoke,且返回Task
        //该方法参数也可以注入,不过建议全都在构造函数中注入,Invoke方法只保留一个HttpContext参数
        public async Task Invoke(HttpContext context)
        {
            _watch?.Start();
            await _next.Invoke(context); //调用后面中间件

            //后面中间件都调用完成后记录花费时间
            await context.Response.WriteAsync($"<div class=\"alert alert-info\" rol=\"alert\">共耗时:{_watch.GetMillionSeconds()} 毫秒</div>");
        }