158 lines
5.3 KiB
C#
158 lines
5.3 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using Microsoft.AspNetCore.Authentication.Negotiate;
|
|
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.AppAuth.Services;
|
|
using MP.Data.Services;
|
|
using MP.Land.Data;
|
|
using MP.TaskMan.Services;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Land
|
|
{
|
|
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)
|
|
{
|
|
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(Configuration.GetValue<string>("SpecialConf:AppUrl"));
|
|
|
|
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");
|
|
|
|
// 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;
|
|
});
|
|
|
|
|
|
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
|
|
.AddNegotiate();
|
|
|
|
services.AddAuthorization(options =>
|
|
{
|
|
// By default, all incoming requests will be authorized according to the default policy.
|
|
options.FallbackPolicy = options.DefaultPolicy;
|
|
});
|
|
|
|
// REDIS setup
|
|
string connStringRedis = Configuration.GetConnectionString("Redis");
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
|
|
services.AddLocalization();
|
|
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
services.AddSingleton<LicenseService>();
|
|
services.AddSingleton<SyncService>();
|
|
services.AddSingleton<RestCallService>();
|
|
services.AddSingleton<TaskService>();
|
|
services.AddSingleton<TabDataService>();
|
|
services.AddSingleton<LandDataService>();
|
|
|
|
services.AddScoped<AppAuthService>();
|
|
services.AddScoped<LMessageService>();
|
|
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
services.AddBlazoredLocalStorage();
|
|
services.AddBlazoredSessionStorage();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |