0

I have a couple of strange problems with the Blazor server running on IIS.

  1. Getting error: Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'. This happens on all servers, i.e., IIS, IIS Express and Kestrel. However, using a Blazor server template application doesn't have the timeout issue.

  2. Running Kestrel for development, the browser has the connection closed on the SSL port but works on the HTTP port with the error: https://localhost:5101/my-tags This site can’t be reached localhost unexpectedly closed the connection. This happens on the template application for Kelstrel on https as well.

I am kind of at witts end. #1 is causing problems in production, whereas #2 is just a minor pain but could be related.

Here are the launch settings:

"profiles": {
  "JBFTags": {
    "commandName": "Project",
    "launchBrowser": true,
    "launchUrl": "my-tags?login=jMVt+ABJXf87QX52eeGLOGAnA6BPYUPMnoqaZUiVvoc=",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    },
    "dotnetRunMessages": true,
    "applicationUrl": "https://localhost:5101;http://localhost:5100"
  },
  "JBFTagshttponly": {
    "commandName": "Project",
    "launchBrowser": true,
    "launchUrl": "my-tags?login=jMVt+ABJXf87QX52eeGLOGAnA6BPYUPMnoqaZUiVvoc=",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    },
    "dotnetRunMessages": true,
    "applicationUrl": "http://localhost:5100"
  },
  "IIS Express": {
    "commandName": "IISExpress",
    "launchBrowser": true,
    "launchUrl": "my-tags?login=m57T6dYR2EjA==",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
    }
  }
},
"iisSettings": {
  "windowsAuthentication": false,
  "anonymousAuthentication": true,
  "iisExpress": {
    "applicationUrl": "http://localhost:19716",
    "sslPort": 44396
  }
}
}

Here is the program.cs

using NLog;

var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Info("JBF Web App started!");
var builder = WebApplication.CreateBuilder(args);

try
{
    // file gets locked so close it in case it's open
    try
    {
        var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Telerik Reporting", "WebReportDesignerSettings.json");
        File.Create(path).Close();
    }
    catch (Exception ex)
    {
        logger.Warn("Path error:  {0}", ex.Message);
    }

    // Add services to the container.
    builder.Services.AddCors(c =>
    {
        c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
    });

    builder.Services.AddScoped<SizeService>();
    builder.Services.AddServerSideBlazor()
        .AddHubOptions(options =>
        {
            options.ClientTimeoutInterval = TimeSpan.FromMinutes(2); // Client timeout
            options.HandshakeTimeout = TimeSpan.FromMinutes(2); // Handshake timeout
            options.KeepAliveInterval = TimeSpan.FromMinutes(1); // Keep-alive interval
        });
    builder.Services.AddScoped<DialogService>();
    builder.Services.AddScoped<NotificationService>();
    builder.Services.AddScoped<TooltipService>();
    builder.Services.AddScoped<ContextMenuService>();
    builder.Services.AddScoped<IMyIdService, MyIdService>();
    builder.Services.AddScoped<SelectedTagsService>();
    builder.Services.AddScoped<JSServices>();
    builder.Services.AddScoped<ICookieService, CookieService>();
    builder.Services.AddHttpContextAccessor();
    builder.Services.AddSingleton<UserAgentDetecter>();
    builder.Services.AddSingleton<HostService>();
    builder.Services.AddSingleton<ExportService>();
    builder.Services.AddSingleton<TagsSqlService>();
    builder.Services.AddScoped<IIdentitySQLService, IdentitySQLService>();
    builder.Services.AddScoped<ToasterService>();
    builder.Services.AddScoped<ITagsEFRepo, TagsEFRepo>();
    builder.Services.AddScoped<IAspNetEfRepo, AspNetEfRepo>();

    builder.Services.AddControllers();
    builder.Services.AddRazorPages().AddNewtonsoftJson();

    builder.Services.AddDbContext<TagDbContext>(options =>
        options.UseSqlServer(builder.Configuration.GetConnectionString("JBFSqlServer2005")));

    builder.Services.AddDbContext<AspNetDbContext>(options =>
        options.UseSqlServer(builder.Configuration.GetConnectionString("JBFASPNETDB")));

    var reportsPath = Path.Combine(builder.Environment.ContentRootPath, "Reports");

    // Configure dependencies for ReportsController.
    builder.Services.TryAddSingleton<IReportServiceConfiguration>(sp =>
        new ReportServiceConfiguration
        {
            ReportingEngineConfiguration = sp.GetService<IConfiguration>(),
            HostAppId = "JBFTags",
            Storage = new FileStorage(),
            ReportSourceResolver = new TypeReportSourceResolver()
                .AddFallbackResolver(new UriReportSourceResolver(reportsPath))
        });

    builder.Services.AddCors(options =>
    {
        options.AddPolicy("AllowBlazorOrigin", builder =>
        {
            builder.WithOrigins("http://localhost:5000", "https://localhost:5001")
                   .AllowAnyHeader()
                   .AllowAnyMethod();
        });
    });

    // Configure dependencies for ReportDesignerController.
    builder.Services.TryAddSingleton<IReportDesignerServiceConfiguration>(sp => new ReportDesignerServiceConfiguration
    {
        DefinitionStorage = new FileDefinitionStorage(reportsPath, new[] { "Resources", "Shared Data Sources" }),
        ResourceStorage = new ResourceStorage(Path.Combine(reportsPath, "Resources")),
        SharedDataSourceStorage = new FileSharedDataSourceStorage(Path.Combine(reportsPath, "Shared Data Sources")),
        SettingsStorage = new FileSettingsStorage(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Telerik Reporting"))
    });

    // NLog: Setup NLog for Dependency injection
    builder.Logging.ClearProviders();
    builder.Host.UseNLog();
    var app = builder.Build();

    // Configure the HTTP request pipeline.
    app.UseCors(options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
    app.UseCors("AllowBlazorOrigin");

    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        app.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseStaticFiles();

    app.UseRouting();
    app.MapControllers();
    app.MapBlazorHub();
    app.MapFallbackToPage("/_Host");
    app.UseWebSockets();

    app.Run();

    // Log the ports the application is listening on
    logger.Info("listing ports");
    var serverAddresses = app.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>();
    foreach (var address in serverAddresses.Addresses)
    {
        logger.Info("Listening on: {0}", address);
    }
}
catch (Exception e)
{
    logger.Error(e, "Stopped program because of exception");
    throw;
}
finally
{
    NLog.LogManager.Shutdown();
}

Netstat output and OS Version TCP 127.0.0.1:5100 0.0.0.0:0 LISTENING *** HTTP TCP 127.0.0.1:5101 0.0.0.0:0 LISTENING *** HTTPS

$ systeminfo | grep OS OS Name: Microsoft Windows Server 2022 Standard OS Version: 10.0.20348 N/A Build 20348 OS Manufacturer: Microsoft Corporation OS Configuration: Standalone Server OS Build Type: Multiprocessor Free BIOS Version: Proxmox distribution of EDK II 4.2023.08-4, 2/15/2024

4
  • could you remove some of the duplicate code from your program.cs file. after how many seconds you are getting this error or you are directory getting it while you access the site? have you checked the console logs is there anything you found there? Commented Feb 24 at 10:59
  • als check the event viewer logs Commented Feb 24 at 12:37
  • Dups have been removed. The connection disconnect happens every 30 sec when idle. Commented Feb 24 at 19:32
  • have you tried different port number for https ? have you checked event viewer logs ? what is the iis recycling setting ? set options.KeepAliveInterval = TimeSpan.FromSeconds(90); what is the iis connection time , idle time out of app pool ? Commented Feb 25 at 14:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.