emptygif
语言: 简体中文

所有语言和框架

ASP.NET Core Minimal API C#

一个用于 ASP.NET Core Minimal API 的 C# 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

ASP.NET Core Minimal API C#

安装
dotnet new web
文件
Program.cs
运行
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");

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: ASP.NET Core Minimal API

更多 C# 示例