terça-feira, 4 de julho de 2023

ASP.NET Response Compression

 

//public void ConfigureServices(IServiceCollection services)

services.AddResponseCompression(options =>

{

    options.MimeTypes = new[] { "application/json" };

    //options.EnableForHttps = true;

});

// ...

// public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceScopeFactory scopeFactory)

app.UseResponseCompression();


Beware of the security issues when using EnableForHttps .

ASP.NET 8 Rate Limit - AddTokenBucketLimiter

 

builder.Services.AddRateLimiter(o =>

{

    o.AddTokenBucketLimiter("token", y =>

    {

        y.TokenLimit = 100;

        y.QueueProcessingOrder = System.Threading.RateLimiting.QueueProcessingOrder.OldestFirst;

        y.QueueLimit = 5;

        y.ReplenishmentPeriod = TimeSpan.FromSeconds(10);

        y.TokensPerPeriod = 20;

        y.AutoReplenishment = true;

    });

});


Source: https://twitter.com/mjovanovictech/status/1676185657092317187

How to get QueryString in .NET 8 Blazor using [SupplyParameterFromQuery]

To read a query string value, there is the  [Parameter] [SupplyParameterFromQuery]


@page "/"

<span>MyValue: @MyValue</span>

@code 

{

    [Parameter]

    [SupplyParameterFromQuery]

    public string MyValue { get; set; }

}


Source: Weston Walker on Twitter: "TIL in .NET Blazor you can get query strings from the URL and set them to a variable with the [SupplyParameterFromQuery] attribute. I'm finding it super handy for Oauth callback scenarios where you get a code back in the url from a external service. https://t.co/ERvhlQOlC1" / Twitter