Files
mapo-core/MP.Prog/Startup.cs
T
Samuele Locatelli 9959d0392a Cleanup commenti
2024-05-09 13:06:06 +02:00

141 lines
4.8 KiB
C#

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MP.Prog.Data;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
namespace MP.Prog
{
public class Startup
{
#region Public Constructors
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
#endregion Public Constructors
#region Public Properties
public IConfiguration Configuration { get; }
#endregion Public Properties
#region Public Methods
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//app.UseMigrationsEndPoint();
}
else
{
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");
//// Registrazione Elmah:
//// https://github.com/ElmahCore/ElmahCore
//app.UseElmah();
// fix forwarders
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
//app.UseAuthentication();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
//app.UseAuthentication();
//app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
//endpoints.MapControllers();
endpoints.MapBlazorHub();
//endpoints.MapHealthChecksUI();
//endpoints.MapHealthChecks("/health", new HealthCheckOptions
//{
// Predicate = _ => true,
// ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
//});
endpoints.MapFallbackToPage("/_Host");
});
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
// cookie applicazione da 14 gg (defaul) a 30
services.ConfigureApplicationCookie(o =>
{
o.ExpireTimeSpan = TimeSpan.FromDays(30);
o.SlidingExpiration = true;
});
//// Elmah
//services.AddElmah();
//string elmaConn = "Data Source=SQL2016DEV;Initial Catalog=Elmah;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=SHERPA.BBM;";
//services.AddElmah<SqlErrorLog>(options =>
//{
// options.ConnectionString = elmaConn;
//});
services.AddStackExchangeRedisCache(options =>
{
//options.Configuration = "localhost:6379";
options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } };
options.InstanceName = "MP:Prog";
});
services.AddLocalization();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<IConfiguration>(Configuration);
//services.AddTransient<Services.BlazorTimer>();
//services.AddSingleton<FileArchDataService>();
services.AddScoped<FileArchDataService>();
services.AddScoped<MessageService>();
}
#endregion Public Methods
}
}