emptygif
Idioma: Español

Todos los lenguajes y frameworks

ASP.NET Core Minimal API C#

Un fragmento en C# para ASP.NET Core Minimal API que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

ASP.NET Core Minimal API C#

Instalar
dotnet new web
Archivo
Program.cs
Ejecutar
dotnet run
var gif = Convert.FromBase64String("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");

var app = WebApplication.CreateBuilder(args).Build();

app.MapGet("/pixel.gif", (HttpResponse response) =>
{
    response.Headers.CacheControl = "no-store";
    return TypedResults.Bytes(gif, "image/gif");
});

app.Run("http://0.0.0.0:8080");

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

curl -sI http://localhost:8080/pixel.gif

Sitio oficial: ASP.NET Core Minimal API

Más en C#