-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
58 lines (44 loc) · 1.68 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
using Microsoft.EntityFrameworkCore;
using ScholarStack.Models;
using ScholarStack.Data;
using ScholarStack.Services;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddSingleton<DB_Manager>();
builder.Services.AddDbContext<ScholarStackDBContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))
);
builder.Services.AddDistributedMemoryCache(); // Add a distributed cache for storing session data
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30); // Set the session timeout duration
options.Cookie.HttpOnly = true; // Ensure the session cookie is accessible only through HTTP
options.Cookie.IsEssential = true; // Make the session cookie essential for authentication and authorization
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<VoteService>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<PrivilegeService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
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();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseStatusCodePagesWithReExecute("/errors/{0}");
app.UseSession();
app.UseMiddleware<AuthenticationMiddleware>();
app.UseRouting();
app.UseAuthorization();
// Map API routes
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // Map all API controllers
});
app.MapRazorPages();
app.Run();