-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
80 lines (72 loc) · 2.63 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Session;
using Serilog;
using theCoffeeroom.Services.Helpers;
using WebMarkupMin.AspNetCore7;
using WebMarkupMin.Core;
var builder = WebApplication.CreateBuilder(args);
//registering services
builder.Services.AddControllersWithViews();
builder.Services.AddSession(options =>
{
options.Cookie.Name = ".coffeebreak.Session";
options.IdleTimeout = TimeSpan.FromSeconds(3600);
});
//DA service
//builder.Services.AddScoped<IDataAccessRepo, DataAccessRepo>();
//builder.Services.AddScoped<IAvatarRepo, AvatarRepo>();
//builder.Services.AddSingleton<SqlService>(provider =>
//{
// string connectionString = ConfigHelper.NewConnectionString.ToString();
// return new SqlService(connectionString);
//});
builder.Services.AddSingleton<SqlService>();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.ExpireTimeSpan = TimeSpan.FromDays(150);
options.SlidingExpiration = true; // Extend the expiration time with each request
});
builder.Services.AddWebMarkupMin(options =>
{
options.AllowMinificationInDevelopmentEnvironment = false;
options.AllowCompressionInDevelopmentEnvironment = false;
})
.AddHtmlMinification(options =>
{
options.MinificationSettings.PreserveNewLines = false;
options.MinificationSettings.MinifyEmbeddedCssCode = true;
options.MinificationSettings.RemoveHtmlComments = true;
options.MinificationSettings.WhitespaceMinificationMode = WhitespaceMinificationMode.Safe;
options.MinificationSettings.RemoveHtmlCommentsFromScriptsAndStyles = true;
options.MinificationSettings.MinifyEmbeddedJsCode = true;
})
.AddXmlMinification()
.AddHttpCompression();
var app = builder.Build();
//logger de serilog (console + file sink)
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Async(writeTo => writeTo.Console())
.WriteTo.Async(a => a.File("Logs/coffeelog.txt", rollingInterval: RollingInterval.Day))
.CreateLogger();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseMiddleware<SessionMiddleware>();
app.UseSession();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseWebMarkupMin();
app.UseRouting();
app.UseAuthorization();
app.UseCookieCheckMiddleware();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapFallbackToFile("nice.html");
app.Run();