91 lines
2.3 KiB
C#
91 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Identity.Client;
|
|
using Radzen;
|
|
using VPKI.Library.Config;
|
|
using VPKI.Library.Services;
|
|
using VPKI.Web.Client.Components;
|
|
using VPKI.Web.Client.Services;
|
|
|
|
string configDir = @"../Config";
|
|
|
|
if (Log4net.IsConfigLoad == true)
|
|
{
|
|
Log4net.WriteLine("Log4net Init Success");
|
|
Log4net.AutoRemoveLog();
|
|
}
|
|
else
|
|
{
|
|
Log4net.WriteLine("Log4net Init Failed", LogType.Error);
|
|
}
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddRadzenComponents();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
//singleton
|
|
builder.Services.AddSingleton<ConfigService<WebClientConfig>>();
|
|
|
|
builder.Services.AddAuthentication();
|
|
builder.Services.AddCascadingAuthenticationState();
|
|
builder.Services.AddScoped<AuthenticationStateProvider, ExtendAuthenticationStatProvicer>();
|
|
|
|
builder.Services.AddOutputCache();
|
|
|
|
//scope
|
|
builder.Services.AddScoped<ApiService>();
|
|
builder.Services.AddScoped<CertificateService>();
|
|
builder.Services.AddScoped<VpkiDialogService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
//read client config and set
|
|
string serverUrl = string.Empty;
|
|
var configService = app.Services.GetService<ConfigService<WebClientConfig>>();
|
|
bool isIIS = false;
|
|
if (configService?.OpenConfig($@"{configDir}/VPKI.WebClientConfig.json") == true)
|
|
{
|
|
Log4net.WriteLine("WebClient Config Success.");
|
|
var clientConfig = ConfigService<WebClientConfig>.Config;
|
|
serverUrl = $"{clientConfig?.Server?.Address}:{clientConfig?.Server?.Port}";
|
|
isIIS = clientConfig!.Server.IIS;
|
|
}
|
|
else
|
|
{
|
|
Log4net.WriteLine("WebClient Config Error.");
|
|
return;
|
|
}
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
Log4net.WriteLine($"IsDevelopment:{app.Environment.IsDevelopment()}");
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// 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.UseAntiforgery();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
if (isIIS == true)
|
|
{
|
|
app.Run();
|
|
}
|
|
else
|
|
{
|
|
Log4net.WriteLine($"Operation Url: {serverUrl}");
|
|
app.Run($"{serverUrl}");
|
|
}
|