2346c67f3a
Divisione aree Redis tra app (x TaskMan in particolare) Test apertura app
197 lines
7.1 KiB
C#
197 lines
7.1 KiB
C#
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 Microsoft.OpenApi.Models;
|
|
using MP.Prog.Data;
|
|
using MP.TaskMan.Services;
|
|
using NLog;
|
|
using StackExchange.Redis;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text.Json.Serialization;
|
|
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)
|
|
{
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(Configuration.GetValue<string>("SpecialConf:AppUrl"));
|
|
|
|
if (env.IsDevelopment() || env.IsStaging())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
// valido solo in sviluppo
|
|
app.UseSwagger(c =>
|
|
{
|
|
c.RouteTemplate = "/swagger/{documentName}/swagger.json";
|
|
});
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
c.SwaggerEndpoint("v1/swagger.json", "MP-PROG.Api");
|
|
});
|
|
}
|
|
|
|
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)
|
|
{
|
|
services.AddControllers();
|
|
services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "MP-PROG.Api", Version = "v1" });
|
|
// Set the comments path for the Swagger JSON and UI.
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
|
|
c.IncludeXmlComments(xmlPath);
|
|
});
|
|
// Aggiunta auth windows
|
|
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;
|
|
});
|
|
|
|
//// 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;
|
|
//});
|
|
|
|
#if false
|
|
services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
//options.Configuration = "localhost:6379";
|
|
options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions() { KeepAlive = 180, DefaultDatabase = 5, EndPoints = { { "localhost", 6379 } } };
|
|
options.InstanceName = "MP:Prog";
|
|
});
|
|
#endif
|
|
// 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.AddControllers()
|
|
.AddJsonOptions(c => c.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
|
|
|
services.AddLocalization();
|
|
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
services.AddSingleton<RestCallService>();
|
|
services.AddSingleton<TaskService>();
|
|
//services.AddSingleton<FileArchDataService>();
|
|
|
|
services.AddScoped<FileArchDataService>();
|
|
services.AddScoped<MessageService>();
|
|
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |