emptygif
Language: English

All languages and frameworks

ASP.NET Core Minimal API C#

A C# snippet for ASP.NET Core Minimal API that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

ASP.NET Core Minimal API C#

Install
dotnet new web
File
Program.cs
Run
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");

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: ASP.NET Core Minimal API

More in C#