public async Task Invoke(HttpContext context) { await context.Response.WriteAsync($"Hello World! Your lucky number is {_numberMaker.MakeNumber()}!!!"); await _next(context); await context.Response.WriteAsync($"Hello World! Your lucky number is {_numberMaker.MakeNumber()}!!!"); }
public async Task Invoke(HttpContext context) { await context.Response.WriteAsync($"Your number is: {_numberMaker.MakeNumber()}"); await context.Response.WriteAsync($"Your number is: {_numberMaker.MakeNumber()}"); await context.Response.WriteAsync($"Your number is: {_numberMaker.MakeNumber()}"); await _next(context); }
public async Task Invoke(HttpContext context) { await context.Response.WriteAsync($"I hope your number is over 9000. Here it is: {_numberMaker.MakeNumber()}"); await _next(context); }
public async Task Invoke(HttpContext context) { var originalOutputStream = context.Response.Body; var replacementOutputStream = new MemoryStream(); context.Response.Body = replacementOutputStream; await _next(context); context.Response.Body = originalOutputStream; replacementOutputStream.Position = 0; using (var sr = new StreamReader(replacementOutputStream)) { var streamDump = await sr.ReadToEndAsync(); if (context.Items["injected"] != null) { var injectedGuid = (string)context.Items["injected"]; streamDump = streamDump.Replace(injectedGuid, $"This has been injected from the middleware! Your lucky number is {_numberMaker.MakeNumber()}"); } var replacedBytes = Encoding.ASCII.GetBytes(streamDump); await context.Response.Body.WriteAsync(replacedBytes, 0, replacedBytes.Length); } }