public async Task Invoke(HttpContext context) { _searchPageUrl = _searchPageUrl ?? "/s"; //execute only if its search page requested if (context.Request.Path == _searchPageUrl) { var searchTerm = context.Request.Query["search"].FirstOrDefault(); if (!searchTerm.IsNullEmptyOrWhiteSpace()) { //do the tracking var term = _searchTermService.FirstOrDefault(x => x.Term == searchTerm) ?? new SearchTerm() { Term = searchTerm }; term.Score++; _searchTermService.InsertOrUpdate(term); } } await _next(context); }