100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
|
using System.Globalization;
|
||
|
using BlueWest.Data.Auth;
|
||
|
using BlueWest.Views.Utils;
|
||
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||
|
using Microsoft.AspNetCore.Localization;
|
||
|
|
||
|
namespace BlueWest.Views;
|
||
|
|
||
|
public class Startup
|
||
|
{
|
||
|
private readonly IConfiguration _configuration;
|
||
|
private readonly IWebHostEnvironment _environment;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Startup ctor
|
||
|
/// </summary>
|
||
|
public Startup(IConfiguration configuration, IWebHostEnvironment hostEnvironment)
|
||
|
{
|
||
|
_configuration = configuration;
|
||
|
_environment = hostEnvironment;
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// Configure Services
|
||
|
/// </summary>
|
||
|
/// <param name="services">Dependency injection</param>
|
||
|
public void ConfigureServices(IServiceCollection services)
|
||
|
{
|
||
|
services.AddSingleton<LayoutCache>();
|
||
|
// Add services to the container.
|
||
|
|
||
|
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||
|
.AddJsonFile("config.json")
|
||
|
.Build();
|
||
|
|
||
|
services.Configure<CookiePolicyOptions>(options =>
|
||
|
{
|
||
|
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||
|
options.CheckConsentNeeded = context => true;
|
||
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||
|
});
|
||
|
|
||
|
services.AddLogging(builder =>
|
||
|
{
|
||
|
builder.AddSimpleConsole();
|
||
|
});
|
||
|
|
||
|
services.AddSession(options =>
|
||
|
{
|
||
|
options.Cookie.Domain = SessionConstants.CookieDomain;
|
||
|
options.Cookie.HttpOnly = true;
|
||
|
});
|
||
|
services.AddControllersWithViews(x => x.EnableEndpointRouting = false);
|
||
|
|
||
|
services.AddSession(options => options.IdleTimeout = TimeSpan.FromHours(8));
|
||
|
|
||
|
|
||
|
services.AddAuthServerServices(_configuration, _environment, configuration);
|
||
|
services.PrepareMySqlDatabasePool(_configuration, _environment, configuration);
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||
|
/// </summary>
|
||
|
/// <param name="app">Object with the necessary data to configure an application's request pipeline</param>
|
||
|
/// <param name="env">Provides information about the web hosting environment an application is running in.</param>
|
||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||
|
{
|
||
|
|
||
|
// Configure the HTTP request pipeline.
|
||
|
if (!env.IsDevelopment())
|
||
|
{
|
||
|
app.UseExceptionHandler("/Home/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();
|
||
|
}
|
||
|
|
||
|
app.UseHttpsRedirection();
|
||
|
app.UseStaticFiles();
|
||
|
|
||
|
app.UseRouting();
|
||
|
|
||
|
app.UseRequestLocalization(options =>
|
||
|
{
|
||
|
var supportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
|
||
|
options.DefaultRequestCulture = new RequestCulture("en-GB");
|
||
|
options.SupportedCultures = supportedCultures;
|
||
|
options.SupportedUICultures = supportedCultures;
|
||
|
});
|
||
|
|
||
|
app.UseAuthentication();
|
||
|
app.UseAuthorization();
|
||
|
app.UseSession();
|
||
|
app.UseMvcWithDefaultRoute();
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|