- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
33 lines (26 loc) · 822 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
26
27
28
29
30
31
32
33
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
varapp=builder.Build();
app.UseMiddleware<GreeterMiddleware>();
app.MapRazorPages();
app.Run();
publicclassGreeterMiddleware
{
RequestDelegate_next;
readonlyLinkGenerator_linkGenerator;
publicGreeterMiddleware(RequestDelegatenext,LinkGeneratorlinkGenerator)
{
_next=next;
_linkGenerator=linkGenerator;
}
publicasyncTaskInvokeAsync(HttpContexthttpContext)
{
EndpointendPoint=httpContext.GetEndpoint();
if(endPoint.DisplayName=="/about")
{
httpContext.Items.Add("GreetingFromMiddleWare","Hello world from GreetingMiddleware");
}
await_next.Invoke(httpContext);
}
}