116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using GPW.CORE.Data;
|
|
using GPW.CORE.Data.Services;
|
|
using GPW.CORE.WRKLOG.Components;
|
|
using Microsoft.AspNetCore.Authentication.Negotiate;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using NLog;
|
|
using NLog.Web;
|
|
using Radzen;
|
|
using StackExchange.Redis;
|
|
using System.Globalization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var logger = LogManager.Setup()
|
|
.LoadConfigurationFromAppSettings()
|
|
.GetCurrentClassLogger();
|
|
|
|
logger.Info("Program.cs: startup");
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
|
.AddNegotiate();
|
|
|
|
builder.Services.AddAuthorization(options =>
|
|
{
|
|
// By default, all incoming requests will be authorized according to the default policy.
|
|
options.FallbackPolicy = options.DefaultPolicy;
|
|
});
|
|
logger.Info("Add Auth");
|
|
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
// REDIS setup
|
|
logger.Info("Setup REDIS");
|
|
string connStringRedis = configuration.GetConnectionString("Redis") ?? "localhost:6379,DefaultDatabase=15";
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
builder.Services.AddSingleton<GpwDataService>();
|
|
builder.Services.AddSingleton<LicenseService>();
|
|
builder.Services.AddScoped<MessageService>();
|
|
builder.Services.AddBlazoredLocalStorage();
|
|
builder.Services.AddBlazoredSessionStorage();
|
|
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
// abilitazione x email management con MailKit
|
|
builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
|
|
|
builder.Services.Configure<MailKitEmailSenderOptions>(options =>
|
|
{
|
|
options.Host_Address = configuration["ExternalProviders:MailKit:SMTP:Address"]!;
|
|
options.Host_Port = Convert.ToInt32(configuration["ExternalProviders:MailKit:SMTP:Port"]);
|
|
options.Host_Username = configuration["ExternalProviders:MailKit:SMTP:Account"]!;
|
|
options.Host_Password = configuration["ExternalProviders:MailKit:SMTP:Password"]!;
|
|
options.Sender_EMail = configuration["ExternalProviders:MailKit:SMTP:SenderEmail"]!;
|
|
options.Sender_Name = configuration["ExternalProviders:MailKit:SMTP:SenderName"]!;
|
|
});
|
|
|
|
builder.Services.AddHttpContextAccessor();
|
|
|
|
// aggiunto compressione
|
|
builder.Services.AddResponseCompression(options =>
|
|
{
|
|
options.EnableForHttps = true;
|
|
});
|
|
|
|
// aggiunta componenti Radzen
|
|
builder.Services.AddRadzenComponents();
|
|
|
|
var app = builder.Build();
|
|
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(configuration.GetValue<string>("ServerConf:BaseUrl"));
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseResponseCompression();
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
// cultura IT...
|
|
var supportedCultures = new[]{
|
|
new CultureInfo("it-IT")
|
|
};
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("it-IT"),
|
|
SupportedCultures = supportedCultures,
|
|
FallBackToParentCultures = false
|
|
});
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
app.UseAntiforgery();
|
|
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
logger.Info("Run App");
|
|
app.Run();
|