CodeLiturgy.Dashboard/BlueWest.Views/Program.cs

66 lines
1.8 KiB
C#
Raw Normal View History

2022-09-26 04:05:23 +03:00
using BlueWest.Views.Utils;
using System.Globalization;
2022-09-27 20:12:13 +03:00
using BlueWest.Data.Auth;
2022-09-26 04:05:23 +03:00
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Options;
2022-09-19 05:50:15 +03:00
var builder = WebApplication.CreateBuilder(args);
2022-09-26 04:05:23 +03:00
builder.Services.AddSingleton<LayoutCache>();
2022-09-19 05:50:15 +03:00
// Add services to the container.
2022-09-26 04:05:23 +03:00
builder.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;
});
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(cookieOptions => {
cookieOptions.LoginPath = "/";
});
2022-09-27 20:12:13 +03:00
builder.Services.AddLogging(builder =>
{
builder.AddSimpleConsole();
});
builder.Services.AddSession(options =>
{
options.Cookie.Domain = SessionConstants.CookieDomain;
options.Cookie.HttpOnly = true;
});
2022-09-19 05:50:15 +03:00
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.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();
2022-09-26 04:05:23 +03:00
app.UseRequestLocalization(options =>
{
var supportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
options.DefaultRequestCulture = new RequestCulture("en-GB");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
2022-09-19 05:50:15 +03:00
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();