public override void OnActionExecuting(ActionExecutingContext context) { Task.Run(async() => { var url = context.HttpContext.Request.Path.Value; var ip = context.HttpContext.Connection.RemoteIpAddress.ToString(); var browser = context.HttpContext.Request.Headers["User-Agent"].ToString(); var query = context.HttpContext.Request.QueryString.Value.Trim('?'); string param; using (var reader = new StreamReader(context.HttpContext.Request.Body)) { param = await reader.ReadToEndAsync(); } await _logService.AddLogRequest(url, DateTime.Now, ip, browser, query, param); }); }
public async Task Invoke(HttpContext httpContext) { Task.Run(async() => { var url = httpContext.Request.Path.Value; var ip = httpContext.Connection.RemoteIpAddress.ToString(); var browser = httpContext.Request.Headers["User-Agent"].ToString(); var query = httpContext.Request.QueryString.Value.Trim('?'); string param; using (var reader = new StreamReader(httpContext.Request.Body)) { param = await reader.ReadToEndAsync(); } await _logService.AddLogRequest(url, DateTime.Now, ip, browser, query, param); }); await _next(httpContext); }