@@ -107,17 +107,7 @@ private static void Main(string[] args)
107107
108108
109109
110- builder . Services . Configure < ForwardedHeadersOptions > ( options =>
111- {
112- options . ForwardedHeaders =
113- ForwardedHeaders . XForwardedFor | ForwardedHeaders . XForwardedProto ;
114-
115- // Only loopback proxies are allowed by default.
116- // Clear that restriction because forwarders are enabled by explicit
117- // configuration.
118- options . KnownIPNetworks . Clear ( ) ;
119- options . KnownProxies . Clear ( ) ;
120- } ) ;
110+ builder . Services . AddTrustedForwardedHeaders ( builder . Configuration , builder . Environment ) ;
121111
122112 ConfigurationManager configuration = builder . Configuration ;
123113 string connectionString = builder . Configuration . GetConnectionString ( "EssentialCSharpWebContextConnection" ) ?? throw new InvalidOperationException ( "Connection string 'EssentialCSharpWebContextConnection' not found." ) ;
@@ -511,7 +501,7 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
511501 }
512502 app . UseStaticFiles ( ) ;
513503
514- app . UseRouting ( ) ;
504+ app . UseRouting ( ) ;
515505
516506 app . UseWhen (
517507 context => context . Request . Path . StartsWithSegments ( "/mcp" ) ,
@@ -542,10 +532,10 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
542532 await next ( context ) ;
543533 } ) ) ;
544534
545- app . UseRateLimiter ( ) ;
546-
547- app . UseAuthorization ( ) ;
548- app . UseOutputCache ( ) ;
535+ app . UseRateLimiter ( ) ;
536+
537+ app . UseAuthorization ( ) ;
538+ app . UseOutputCache ( ) ;
549539
550540 app . UseMiddleware < ReferralMiddleware > ( ) ;
551541
@@ -584,13 +574,13 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
584574 try
585575 {
586576 SitemapXmlHelpers . EnsureSitemapHealthy ( siteMappingService . SiteMappings . ToList ( ) ) ;
587- LogSitemapValidationSucceeded ( logger ) ;
588- }
589- catch ( Exception ex )
590- {
591- LogSitemapValidationFailed ( logger , ex ) ;
592- // Continue startup even if sitemap validation fails
593- }
577+ LogSitemapValidationSucceeded ( logger ) ;
578+ }
579+ catch ( Exception ex )
580+ {
581+ LogSitemapValidationFailed ( logger , ex ) ;
582+ // Continue startup even if sitemap validation fails
583+ }
594584
595585 app . Run ( ) ;
596586 }
@@ -604,11 +594,11 @@ private static bool IsMcpTransportRequest(HttpRequest request) =>
604594 [ LoggerMessage ( Level = LogLevel . Error , Message = "Unhandled exception on {Path}" ) ]
605595 private static partial void LogUnhandledException ( ILogger < Program > logger , Exception ? exception , PathString path ) ;
606596
607- [ LoggerMessage ( Level = LogLevel . Information , Message = "Sitemap validation completed successfully during application startup" ) ]
608- private static partial void LogSitemapValidationSucceeded ( ILogger < Program > logger ) ;
609-
610- [ LoggerMessage ( Level = LogLevel . Error , Message = "Failed to validate sitemap during application startup" ) ]
611- private static partial void LogSitemapValidationFailed ( ILogger < Program > logger , Exception exception ) ;
597+ [ LoggerMessage ( Level = LogLevel . Information , Message = "Sitemap validation completed successfully during application startup" ) ]
598+ private static partial void LogSitemapValidationSucceeded ( ILogger < Program > logger ) ;
599+
600+ [ LoggerMessage ( Level = LogLevel . Error , Message = "Failed to validate sitemap during application startup" ) ]
601+ private static partial void LogSitemapValidationFailed ( ILogger < Program > logger , Exception exception ) ;
612602
613603 [ LoggerMessage ( Level = LogLevel . Warning , Message = "Ignoring invalid TryDotNet origin in CSP: {Origin}" ) ]
614604 private static partial void LogIgnoringInvalidTryDotNetOrigin ( ILogger logger , string origin ) ;
0 commit comments