-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
156 lines (122 loc) · 6 KB
/
Copy pathProgram.cs
File metadata and controls
156 lines (122 loc) · 6 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using MPCRS.Models;
using MPCRS.Utilities;
using Microsoft.Extensions.FileProviders;
using MPCRS.Services;
namespace MPCRS
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("MPCRS");
// Add services to the container.
//builder.Services.AddResponseCompression(options =>
//{
// options.EnableForHttps = true;
//});
//builder.Services.AddAutoMapper(typeof(Program));
builder.Services.AddControllersWithViews();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowReactApp",
policy =>
{
policy.WithOrigins("http://localhost:3000", "http://localhost:3001")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.SetIsOriginAllowed(origin => true); // Add this
});
});
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(BinderOptions =>
{
BinderOptions.LoginPath = "/Auth/Index";
BinderOptions.AccessDeniedPath = "/Auth/UnAuthorized";
BinderOptions.Cookie.SameSite = SameSiteMode.None; // Add this
BinderOptions.Cookie.SecurePolicy = CookieSecurePolicy.Always; // Add this
});
builder.Services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(240); });
//builder.Services.AddWebOptimizer(minifyJavaScript: false, minifyCss: true);
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
var environmentName = builder.Environment.EnvironmentName;
builder.Configuration
.SetBasePath(currentDirectory)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{environmentName}.json", true, true)
.AddEnvironmentVariables();
builder.Services.AddSingleton<MPDapperContext>();
builder.Services.AddDbContext<DESI_STFE_PRODContext>(options =>
options.UseSqlServer(connectionString)); ;
//// Add a DbContext to store your Database Keys
builder.Services.AddDbContext<MyKeysContext>(options =>
options.UseSqlServer(connectionString));
// using Microsoft.AspNetCore.DataProtection;
builder.Services.AddDataProtection()
.PersistKeysToDbContext<MyKeysContext>();
// Register EmailService
builder.Services.AddScoped<IEmailService, EmailService>();
// Register Email Background Service
builder.Services.AddHostedService<EmailSyncBackgroundService>();
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue; // Set the desired maximum request body size
options.Limits.MaxRequestBufferSize = long.MaxValue;
});
builder.Services.Configure<FormOptions>(options =>
{
options.ValueLengthLimit = int.MaxValue;
options.MultipartBodyLengthLimit = long.MaxValue; // Set the desired maximum multipart body length
options.BufferBodyLengthLimit = long.MaxValue;
});
builder.Services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
options.MaxRequestBodyBufferSize = int.MaxValue;
options.MaxRequestBodySize = long.MaxValue;
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddHttpClient();
builder.Services.AddSingleton<AiAPIService>();
builder.Services.Configure<BubbleDetectionOptions>(
builder.Configuration.GetSection("BubbleDetection"));
var app = builder.Build();
PythonProcessManager.Start(app.Configuration, app.Environment);
//app.UseResponseCompression();
// 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();
app.UseCors("AllowReactApp");
app.UseAuthentication();
app.UseAuthorization();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "v3modules")),
RequestPath = "/v3modules"
});
app.MapControllerRoute(
name: "default",
pattern: "{controller=Auth}/{action=Index}/{id?}");
var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
lifetime.ApplicationStopping.Register(() => PythonProcessManager.Stop());
app.Run();
}
}
}