-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
179 lines (145 loc) · 5.49 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using IMRepo.Data;
using IMRepo.Services.basic;
using JaosLib.Services.JaoTables;
using IMRepo.Services.Utilities;
using JaosLib.Services.Utilities;
using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, configuration) =>
configuration.ReadFrom.Configuration(context.Configuration));
// Add services to the container.
string connectionString = builder.Configuration.GetConnectionString("ServerTest") ?? ""; // Wind ServerTest
builder.Services.AddDbContext<IMRepoDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services
.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<IMRepoDbContext>();
builder.Services.AddControllersWithViews();
//builder.Services.AddSession();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(60); // timeout
//options.Cookie.HttpOnly = true;
//options.Cookie.IsEssential = true;
});
// Project Services
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IPipToolsService, PipToolsService>();
builder.Services.AddTransient<IFileLoadService, FileLoadService>();
builder.Services.AddScoped<IJaoTableServices, JaoTableServices>();
builder.Services.AddScoped<IJaoTableExcelServices, JaoTableExcelServices>();
builder.Services.AddScoped<IExcelPOILib, ExcelPOILib>();
builder.Services.AddScoped<INPOIWordService, NPOIWordService>();
builder.Services.AddScoped<IParentProjectService, ParentProjectService>();
builder.Services.AddScoped<ILogTools, LogTools>();
//For Authentication
builder.Services.Configure<IdentityOptions>(options =>
{
// Password settings.
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 6;
options.Password.RequiredUniqueChars = 0; // change to 1 and all other to true
// Lockout settings.
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.AllowedForNewUsers = true;
// User settings.
options.User.AllowedUserNameCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@$%+#()!*=&";
options.Password.RequireNonAlphanumeric = true;
options.Password.RequireUppercase = true;
options.Password.RequiredLength = 8;
options.Password.RequireLowercase = true;
options.Password.RequireDigit = true;
options.User.RequireUniqueEmail = true;
});
builder.Services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.LoginPath = "/Identity/Account/Login";
options.AccessDeniedPath = "/Identity/Account/AccessDenied";
options.SlidingExpiration = true;
});
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddMvc()
// .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) no localized view files in use
.AddDataAnnotationsLocalization();
//=========================================================================
var app = builder.Build();
//-----------------------------------
// Set language and culture
var supportedCultures = new[]
{
new CultureInfo("es-AR"),
};
var options = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("es-AR", "es-AR"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
};
// Configure the Localization middleware
app.UseRequestLocalization(options);
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
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.UseSession();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
app.MapAreaControllerRoute(
name: "MyAreaReview",
areaName: "Review",
pattern: "Review/{controller=Review}/{action=Index}/{id?}");
app.MapAreaControllerRoute(
name: "MyAreaMonitor",
areaName: "Monitor",
pattern: "Monitor/{controller=Home}/{action=Index}/{id?}");
app.MapAreaControllerRoute(
name: "MyAreaPEU",
areaName: "PEU",
pattern: "PEU/{controller=PEU}/{action=Index}/{id?}");
app.MapAreaControllerRoute(
name: "MyAreaAppReports",
areaName: "AppReports",
pattern: "AppReports/{controller=Pew}/{action=Index}/{id?}");
app.MapAreaControllerRoute(
name: "MyAreaUserAdmin",
areaName: "UserAdmin",
pattern: "UserAdmin/{controller=Home}/{action=Index}/{id?}");
//app.MapControllerRoute(
// name: "default",
// pattern: "{controller=Contract}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.Run();