NET8
This commit is contained in:
@ -1,15 +1,23 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
using Fab2ApprovalSystem.Misc;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
using Fab2ApprovalSystem.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace Fab2ApprovalMKLink;
|
||||
|
||||
@ -24,12 +32,36 @@ public class Program {
|
||||
throw new Exception("Company name must have a value!");
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
throw new Exception("Working directory name must have a value!");
|
||||
GlobalVars.AppSettings = appSettings;
|
||||
GlobalVars.AttachmentUrl = appSettings.AttachmentUrl is null ? string.Empty : appSettings.AttachmentUrl;
|
||||
GlobalVars.CA_BlankFormsLocation = appSettings.CABlankFormsLocation;
|
||||
GlobalVars.DBConnection = appSettings.DBConnection;
|
||||
GlobalVars.DB_CONNECTION_STRING = appSettings.DBConnectionString;
|
||||
GlobalVars.hostURL = appSettings.HostURL;
|
||||
GlobalVars.IS_INFINEON_DOMAIN = appSettings.IsInfineonDomain;
|
||||
GlobalVars.MesaTemplateFiles = appSettings.MesaTemplateFiles;
|
||||
GlobalVars.NDriveURL = appSettings.NDriveURL;
|
||||
GlobalVars.SENDER_EMAIL = appSettings.SenderEmail;
|
||||
GlobalVars.USER_ID = appSettings.UserId;
|
||||
GlobalVars.USER_ISADMIN = appSettings.UserIsAdmin;
|
||||
GlobalVars.WSR_URL = appSettings.WSR_URL;
|
||||
try {
|
||||
_ = webApplicationBuilder.Services.Configure<ApiBehaviorOptions>(options => options.SuppressModelStateInvalidFilter = true);
|
||||
_ = webApplicationBuilder.Services.AddControllers();
|
||||
_ = webApplicationBuilder.Services.AddControllersWithViews();
|
||||
_ = webApplicationBuilder.Services.AddDistributedMemoryCache();
|
||||
_ = webApplicationBuilder.Services.AddHttpClient();
|
||||
_ = webApplicationBuilder.Services.AddMemoryCache();
|
||||
_ = webApplicationBuilder.Services.AddSingleton(_ => appSettings);
|
||||
_ = webApplicationBuilder.Services.AddSingleton<ICompositeViewEngine, CompositeViewEngine>();
|
||||
// _ = webApplicationBuilder.Services.AddTransient<IViewRenderingService, ViewRenderingService>();
|
||||
// _ = webApplicationBuilder.Services.AddScoped<IViewRenderService, ViewRenderService>();
|
||||
// _ = webApplicationBuilder.Services.AddSingleton<ITempDataProvider, ITempDataProvider>();
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
_ = webApplicationBuilder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
|
||||
_ = webApplicationBuilder.Services.AddScoped<IDalService, DalService>();
|
||||
_ = webApplicationBuilder.Services.AddScoped<IDbConnectionService, DbConnectionService>();
|
||||
_ = webApplicationBuilder.Services.AddScoped<IUserService, UserService>();
|
||||
_ = webApplicationBuilder.Services.AddSwaggerGen();
|
||||
_ = webApplicationBuilder.Services.AddSession(sessionOptions => {
|
||||
sessionOptions.IdleTimeout = TimeSpan.FromSeconds(2000);
|
||||
@ -37,6 +69,29 @@ public class Program {
|
||||
sessionOptions.Cookie.IsEssential = true;
|
||||
}
|
||||
);
|
||||
|
||||
_ = webApplicationBuilder.Services.AddAuthentication(options => {
|
||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddJwtBearer(options => {
|
||||
options.RequireHttpsMetadata = false;
|
||||
options.SaveToken = true;
|
||||
options.TokenValidationParameters = new TokenValidationParameters {
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = appSettings.JwtIssuer,
|
||||
ValidateAudience = false,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(appSettings.JwtKey)),
|
||||
ClockSkew = TimeSpan.Zero
|
||||
};
|
||||
});
|
||||
|
||||
_ = webApplicationBuilder.Services.AddAuthorization(options => {
|
||||
options.DefaultPolicy = new AuthorizationPolicyBuilder()
|
||||
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
});
|
||||
if (WindowsServiceHelpers.IsWindowsService()) {
|
||||
_ = webApplicationBuilder.Services.AddSingleton<IHostLifetime, WindowsServiceLifetime>();
|
||||
_ = webApplicationBuilder.Logging.AddEventLog(settings => {
|
||||
@ -65,6 +120,8 @@ public class Program {
|
||||
}
|
||||
_ = webApplication.UseSession();
|
||||
_ = webApplication.MapControllers();
|
||||
_ = webApplication.UseAuthentication();
|
||||
_ = webApplication.UseAuthorization();
|
||||
logger.LogInformation("Starting Web Application");
|
||||
webApplication.Run();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user