Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
63 lines (56 loc) · 2.37 KB
/
Copy pathProgram.cs
File metadata and controls
63 lines (56 loc) · 2.37 KB
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
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using TriviaApp.Models;
public static class ProxySettings
{
public static bool UseProxy = false;
public static string ProxyAddress = "";
public static int ProxyPort = 0;
public static string ProxyUsername = "";
public static string ProxyPassword = "";
}
public static class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var connectionString = builder.Configuration.GetConnectionString("DbContextConnection") ?? throw new
InvalidOperationException("Connection string 'DbContextConnection' not found.");
ProxySettings.UseProxy = builder.Configuration.GetValue<bool>("UseProxy");
if (ProxySettings.UseProxy)
{
ProxySettings.ProxyAddress = builder.Configuration.GetValue<string>("ProxyAddress");
ProxySettings.ProxyPort = builder.Configuration.GetValue<int>("ProxyPort");
ProxySettings.ProxyUsername = builder.Configuration.GetValue<string>("ProxyUsername");
ProxySettings.ProxyPassword = builder.Configuration.GetValue<string>("ProxyPassword");
}
builder.Services.AddDbContext<TriviaContext>(options => options
.UseLazyLoadingProxies()
.UseSqlite(connectionString));
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
options.SlidingExpiration = true;
options.LoginPath = new("/Account/Login");
options.ExpireTimeSpan = TimeSpan.FromDays(30);
options.Cookie.SameSite = SameSiteMode.Strict;
});
WebApplication app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
TriviaApp.TriviaAPI.Client client = new();
app.Run();
}
}