- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathProgram.cs
34 lines (29 loc) · 1.12 KB
/
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
34
varbuilder=WebApplication.CreateBuilder();
builder.Services.AddProblemDetails();
varapp=builder.Build();
app.UseExceptionHandler();
app.Use(async(context,next)=>
{
if(context.Request.Path=="/problems"&&context.RequestServices.GetService<IProblemDetailsService>()is{}problemDetailsService)
{
context.Response.StatusCode=StatusCodes.Status405MethodNotAllowed;
varproblemDetails=newProblemDetailsContext{HttpContext=context};
problemDetails.ProblemDetails.Extensions.Add("custom-property-2",Guid.NewGuid().ToString());
awaitproblemDetailsService.WriteAsync(problemDetails);
return;
}
awaitnext(context);
});
app.MapGet("/",(HttpContextcontext)=>Results.Content($$"""
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<div class="container">
<a href="/problems">Show problems</a>
</div>
</body>
</html>
""","text/html"));
app.Run();