1- #region Copyright notice and license
1+ #region Copyright notice and license
22
33// Copyright 2019 The gRPC Authors
44//
2121using Grpc . Shared ;
2222using Grpc . Testing ;
2323using Grpc . Tests . Shared ;
24- #if NET5_0_OR_GREATER
2524using Microsoft . AspNetCore . Authentication . Certificate ;
26- #endif
2725using Newtonsoft . Json ;
2826
2927namespace GrpcAspNetCoreServer ;
@@ -41,10 +39,8 @@ public void ConfigureServices(IServiceCollection services)
4139 {
4240 services . AddGrpc ( o =>
4341 {
44- #if NET5_0_OR_GREATER
4542 // Small performance benefit to not add catch-all routes to handle UNIMPLEMENTED for unknown services
4643 o . IgnoreUnknownServices = true ;
47- #endif
4844 } ) ;
4945 services . Configure < RouteOptions > ( c =>
5046 {
@@ -54,7 +50,6 @@ public void ConfigureServices(IServiceCollection services)
5450 services . AddSingleton < BenchmarkServiceImpl > ( ) ;
5551 services . AddControllers ( ) ;
5652
57- #if NET5_0_OR_GREATER
5853 bool . TryParse ( _config [ "enableCertAuth" ] , out var enableCertAuth ) ;
5954 if ( enableCertAuth )
6055 {
@@ -67,7 +62,6 @@ public void ConfigureServices(IServiceCollection services)
6762 options . AllowedCertificateTypes = CertificateTypes . All ;
6863 } ) ;
6964 }
70- #endif
7165 }
7266
7367 public void Configure ( IApplicationBuilder app , IHostApplicationLifetime applicationLifetime )
@@ -83,14 +77,12 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat
8377
8478 app . UseRouting ( ) ;
8579
86- #if NET5_0_OR_GREATER
8780 bool . TryParse ( _config [ "enableCertAuth" ] , out var enableCertAuth ) ;
8881 if ( enableCertAuth )
8982 {
9083 app . UseAuthentication ( ) ;
9184 app . UseAuthorization ( ) ;
9285 }
93- #endif
9486
9587#if GRPC_WEB
9688 bool . TryParse ( _config [ "enableGrpcWeb" ] , out var enableGrpcWeb ) ;
@@ -139,12 +131,10 @@ public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicat
139131
140132 private void ConfigureAuthorization ( IEndpointConventionBuilder builder )
141133 {
142- #if NET5_0_OR_GREATER
143134 bool . TryParse ( _config [ "enableCertAuth" ] , out var enableCertAuth ) ;
144135 if ( enableCertAuth )
145136 {
146137 builder . RequireAuthorization ( ) ;
147138 }
148- #endif
149139 }
150140}
0 commit comments