Framework: Net 8
Render mode: InteractiveServer
Issues :
If I start profile Local then after 3-4 times update page I encounter the exception :
but if I start profile TP.Global.Fe.Server all work as expected .
LounchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:19712",
"sslPort": 44395
}
},
"profiles": {
"Local": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Local"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5400"
},
"TP.Global.Fe.Server": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5400",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
appsettings.Local.json
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:5400"
}
}
},
"Settings": {
"AuthAPI": "http://tp-global-auth:5300",
"GlobalAPI": "http://tp-global-api:5100/",
"DataProtectionPath": "/app/data-protection-keys"
}
appsettings.Development.json
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://0.0.0.0:5400"
}
}
},
"Settings": {
"AuthAPI": "http://tp-global-auth:5300",
"GlobalAPI": "http://tp-global-api:5100/",
"DataProtectionPath": "/app/data-protection-keys"
}
app.razer
@inject NavigationManager NavigationManager
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="@NavigationManager.BaseUri" />
<RadzenTheme @rendermode="@InteractiveServer" Theme="standard-dark" />
<link rel="stylesheet" href="css/site.css" />
<link rel="icon" href="favicon.ico" />
<HeadOutlet @rendermode="@InteractiveServer" />
</head>
<body>
<Routes @rendermode="@InteractiveServer" />
<script src="_framework/blazor.web.js"></script>
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script>
</body>
</html>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; }
[Inject]
private ThemeService ThemeService { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
if (HttpContext != null)
{
var theme = HttpContext.Request.Cookies["TP.Global.FeTheme"];
if (!string.IsNullOrEmpty(theme))
{
ThemeService.SetTheme(theme, false);
}
}
}
}
Program.cs
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.IdentityModel.Tokens;
using Radzen;
using System.Text;
using TP.Global.Fe.BeServices;
using TP.Global.Fe.BeServices.AuthAPIService;
using TP.Global.Fe.BeServices.GlobalAPIService;
using TP.Global.Fe.BeServices.GlobalAPIService.ClusterService;
using TP.Global.Fe.BeServices.GlobalAPIService.FileService;
using TP.Global.Fe.BeServices.GlobalAPIService.NodeService;
using TP.Global.Fe.BeServices.GlobalAPIService.PingTraceService;
using TP.Global.Fe.BeServices.GlobalAPIService.ScheduledService;
using TP.Global.Fe.BeServices.GlobalAPIService.SystemService;
using TP.Global.Fe.BeServices.GlobalAPIService.WindowsService;
using TP.Global.Fe.Components;
var builder = WebApplication.CreateBuilder(args);
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
builder
.Configuration
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents().AddHubOptions(options => options.MaximumReceiveMessageSize = 10 * 1024 * 1024);
var validIssuer = builder.Configuration.GetValue<string>("JwtTokenSettings:ValidIssuer");
var validAudience = builder.Configuration.GetValue<string>("JwtTokenSettings:ValidAudience");
var symmetricSecurityKey = builder.Configuration.GetValue<string>("JwtTokenSettings:SymmetricSecurityKey");
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.IncludeErrorDetails = true;
options.TokenValidationParameters = new TokenValidationParameters()
{
ClockSkew = TimeSpan.Zero,
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = validIssuer,
ValidAudience = validAudience,
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(symmetricSecurityKey)
),
};
});
builder.Services.AddOptions();
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddControllers();
builder.Services.AddRadzenComponents();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
});
});
builder.Services.AddRadzenCookieThemeService(options =>
{
options.Name = "TP.Global.FeTheme";
options.Duration = TimeSpan.FromDays(365);
});
builder.Services.AddScoped<DialogService>();
builder.Services.AddMemoryCache();
builder.Services
.AddHttpClient("AuthAPI", client => client.BaseAddress = new Uri(builder.Configuration.GetValue<string>("Settings:AuthAPI")))
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
return handler;
});
builder.Services.AddHttpClient("GlobalAPI", client => client.BaseAddress = new Uri(builder.Configuration.GetValue<string>("Settings:GlobalAPI")))
.ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
return handler;
});
builder.Services.AddScoped<IAuthAPIService, AuthAPIService>();
builder.Services.AddScoped<IGlobalApiService, GlobalAPIService>();
builder.Services.AddScoped<IClusterService, ClusterService>();
builder.Services.AddScoped<IWindowsService, WindowsService>();
builder.Services.AddScoped<IFileService, FileService>();
builder.Services.AddScoped<IPingTraceService, PingTraceService>();
builder.Services.AddScoped<ISystemService, SystemService>();
builder.Services.AddScoped<INodeService, NodeService>();
builder.Services.AddScoped<IScheduledService, ScheduledService>();
builder.Services.AddScoped<ITokenService, TokenService>();
builder.Services.AddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
//builder.Services.AddHttpClient();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!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.UseCors();
app.MapControllers();
app.UseAuthentication();
app.UseAuthorization();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();