99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Authentication.Negotiate;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using SHERPA.AD.Data;
|
|
using StackExchange.Redis;
|
|
using SHERPA.Data;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using System.Globalization;
|
|
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// 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;
|
|
});
|
|
|
|
// configuration setup
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
|
|
// REDIS setup
|
|
string connStringRedis = configuration.GetConnectionString("Redis");
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
// 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.AddStackExchangeRedisCache(options =>
|
|
//{
|
|
// options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 15, EndPoints = { { "localhost", 6379 } } };
|
|
// options.InstanceName = "SHERPA:ADM:";
|
|
//});
|
|
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddServerSideBlazor();
|
|
builder.Services.AddSingleton<SIMDataService>();
|
|
builder.Services.AddScoped<MessageService>();
|
|
builder.Services.AddHttpContextAccessor();
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
builder.Services.AddBlazoredLocalStorage();
|
|
builder.Services.AddBlazoredSessionStorage();
|
|
|
|
var app = builder.Build();
|
|
|
|
// 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();
|
|
}
|
|
|
|
// 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.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapBlazorHub();
|
|
app.MapFallbackToPage("/_Host");
|
|
|
|
app.Run();
|