Only enable SignalR detailed errors in development

Changed EnableDetailedErrors to be conditional based on:
- Debugger attached (DebuggerHelper.IsAttached)
- context.HostingEnvironment.IsDevelopment()

Updated ConfigureServices to accept WebHostBuilderContext to properly
access the hosting environment instead of directly reading environment
variables. This prevents detailed error messages from being exposed in
production builds, which is important for security.
This commit is contained in:
Pierre Arnaud
2026-01-31 10:01:46 +01:00
parent 0ee2bbe31c
commit 38ee6fabb4

View File

@@ -10,6 +10,7 @@
using ElectronNET.Runtime.Helpers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
/// <summary>
/// Provides extension methods for <see cref="IWebHostBuilder"/> to enable Electron.NET
@@ -90,7 +91,7 @@
builder = builder.UseUrls($"http://{host}:{webPort}");
}
builder = builder.ConfigureServices(services =>
builder = builder.ConfigureServices((context, services) =>
{
services.AddTransient<IStartupFilter, ServerReadyStartupFilter>();
services.AddSingleton<AspNetLifetimeAdapter>();
@@ -109,8 +110,10 @@
case StartupMethod.UnpackedDotnetFirstSignalR:
services.AddSignalR(options =>
{
// Enable detailed errors for debugging
options.EnableDetailedErrors = true;
// Enable detailed errors only in development for security
options.EnableDetailedErrors =
DebuggerHelper.IsAttached ||
context.HostingEnvironment.IsDevelopment();
});
services.AddSingleton<IElectronNetRuntimeController, RuntimeControllerAspNetDotnetFirstSignalR>();
break;