198 lines
7.5 KiB
C#
198 lines
7.5 KiB
C#
using LiMan.DB;
|
|
using LiMan.UI.Data;
|
|
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.FileProviders;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.AspNetCore.Authentication.Negotiate;
|
|
using Microsoft.AspNetCore.Http;
|
|
using System.IO;
|
|
using Liman.CadCam.Services;
|
|
using StackExchange.Redis;
|
|
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
|
|
namespace LiMan.UI
|
|
{
|
|
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["RuntimeOpt:BaseUrl"]);
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
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.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
// verifico da conf se sia linux o windows x file da accedere...
|
|
if (Configuration["HostOs"] == "Win")
|
|
{
|
|
app.UseFileServer(new FileServerOptions
|
|
{
|
|
FileProvider = new PhysicalFileProvider(@"\\stor01\TEAM DRIVES\40_FileUpload\unsafe_uploads"),
|
|
RequestPath = new PathString("/unsafe_uploads"),
|
|
EnableDirectoryBrowsing = true
|
|
//EnableDirectoryBrowsing = false
|
|
});
|
|
}
|
|
else
|
|
{
|
|
app.UseFileServer(new FileServerOptions
|
|
{
|
|
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "unsafe_uploads")),
|
|
RequestPath = new PathString("/unsafe_uploads"),
|
|
EnableDirectoryBrowsing = true
|
|
//EnableDirectoryBrowsing = false
|
|
});
|
|
}
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapBlazorHub();
|
|
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)
|
|
{
|
|
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;
|
|
});
|
|
|
|
// cookie applicazione da 14 gg (defaul) a 30
|
|
services.ConfigureApplicationCookie(o =>
|
|
{
|
|
o.ExpireTimeSpan = TimeSpan.FromDays(30);
|
|
o.SlidingExpiration = true;
|
|
});
|
|
|
|
#if false
|
|
services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
//options.Configuration = "localhost:6379";
|
|
options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } };
|
|
options.InstanceName = "LiMan";
|
|
});
|
|
#endif
|
|
|
|
// REDIS setup
|
|
var redisConnString = Configuration.GetConnectionString("Redis");
|
|
string connStringRedis = redisConnString ?? "localhost:6379, DefaultDatabase=1, connectTimeout=5000, syncTimeout=5000, asyncTimeout=5000, abortConnect=false, ssl=false";
|
|
string redisSrvAddr = "127.0.0.1";
|
|
if (connStringRedis.IndexOf(":") >= 0)
|
|
{
|
|
redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
}
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
// Add services x accesso dati
|
|
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
|
|
|
|
// init info x DB
|
|
string dbServerAddr = Configuration["DbConfig:Server"];
|
|
Liman.CadCam.DbConfig.InitDb(dbServerAddr);
|
|
|
|
|
|
// abilitazione x email management con MailKit
|
|
services.AddTransient<IEmailSender, MailKitEmailSender>();
|
|
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"];
|
|
options.Host_SecureSocketOptions = MailKit.Security.SecureSocketOptions.Auto;
|
|
});
|
|
|
|
services.AddLocalization();
|
|
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
services.AddScoped<MessageService>();
|
|
services.AddSingleton<LiManDataService>();
|
|
services.AddSingleton<CadCamService>();
|
|
services.AddBlazoredLocalStorage();
|
|
services.AddBlazoredSessionStorage();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |