- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
25 lines (20 loc) · 768 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddTransient<TerminalMiddleware>();
varapp=builder.Build();
app.UseMiddleware(typeof(TerminalMiddleware));
app.Run();
publicclassTerminalMiddleware:IMiddleware
{
ILogger<TerminalMiddleware>_log;
DateTime_date=DateTime.Now;
publicTerminalMiddleware(ILogger<TerminalMiddleware>log)
{
_log=log;
}
publicasyncTaskInvokeAsync(HttpContextcontext,RequestDelegatenext)
{
_log.LogDebug($"Request: {context.Request.Path}");
context.Response.Headers.Append("Content-Type","text/plain");
awaitcontext.Response.WriteAsync($"This Middleware is transient. Keep refreshing your page. The date will keep changing: {_date}.");
}
}