emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

ASP.NET Core MVC controller C#

Snippet C# untuk ASP.NET Core MVC controller yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

ASP.NET Core MVC controller C#

Instal
dotnet new webapi --use-controllers
File
Program.cs
Jalankan
dotnet run
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

var app = builder.Build();
app.MapControllers();
app.Run("http://0.0.0.0:8080");

[ApiController]
public class PixelController : ControllerBase
{
    private static readonly byte[] Gif = Convert.FromBase64String("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");

    [HttpGet("/pixel.gif")]
    [ResponseCache(NoStore = true)]
    public IActionResult Get() => File(Gif, "image/gif");
}

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: ASP.NET Core MVC controller

Lainnya dalam C#