SummerBestWebForm2/Program.cs

68 lines
1.9 KiB
C#
Raw Normal View History

2025-05-15 06:12:34 -04:00
using Microsoft.AspNetCore.ResponseCompression;
2025-05-30 03:58:16 -04:00
using SummerBestWebForm2.ClassObj;
2025-05-15 05:21:00 -04:00
using SummerBestWebForm2.Components;
2025-05-15 06:12:34 -04:00
using System.IO.Compression;
2025-05-15 05:21:00 -04:00
namespace SummerBestWebForm2
{
2025-05-15 06:12:34 -04:00
public class Program
{
public static void Main(string[] args)
2025-05-15 05:21:00 -04:00
{
2025-05-15 06:12:34 -04:00
var builder = WebApplication.CreateBuilder(args);
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});
builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
});
builder.Services.Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.SmallestSize;
});
builder.Services.AddDataProtection();
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<HttpContextAccessor>();
2025-05-30 03:58:16 -04:00
builder.Services.AddScoped<IPAddressService>(); // IPADDR
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
var app = builder.Build();
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
var webSocketOptions = new WebSocketOptions()
{
KeepAliveInterval = TimeSpan.FromSeconds(15)
};
app.UseWebSockets(webSocketOptions);
app.UseResponseCompression();
app.UseResponseCaching();
2025-05-15 05:21:00 -04:00
2025-05-15 06:12:34 -04:00
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
2025-05-15 05:21:00 -04:00
}
2025-05-15 06:12:34 -04:00
}
2025-05-15 05:21:00 -04:00
}