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# 範例