Вот мой код:
- FallbackMiddleware.cs
Код: Выделить всё
public async Task InvokeAsync(HttpContext context)
{
context.Request.EnableBuffering();
await _next(context); // returns 500
if ((int)context.Response.StatusCode >= 500)
{
// calls an externeral service which returns 200
await _forwarder.SendAsync(context, "http://localhost:5002", _client);
}
}
- 500Controller.cs
Код: Выделить всё
[HttpGet]
public ActionResult Get()
{
return new StatusCodeResult(500);
}
Код: Выделить всё
builder.Services.AddReverseProxy().AddTransforms(m =>
{
m.AddResponseTransform(context =>
{
context.SuppressResponseBody = true;
return default;
});
});
Ссылка:
- Повторная попытка «безопасных» HTTP-запросов.
Подробнее здесь: https://stackoverflow.com/questions/790 ... middleware