From f28b79590817af64aed9b7977bf8888617e37af6 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 22 Nov 2023 15:17:56 +0800 Subject: [PATCH 1/3] Do not use `try catch` to determine the BlazorServer running mode. Resolve #18224 --- .../BlazorServerLookupApiRequestService.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs index 00a5086031..1acda7e066 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs @@ -47,21 +47,19 @@ public class BlazorServerLookupApiRequestService : ILookupApiRequestService, ITr var uri = new Uri(url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) { - var baseUrl = string.Empty; - try + var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Default"); + if (remoteServiceConfig != null) { - //Blazor tiered -- mode - var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default"); - baseUrl = remoteServiceConfig.BaseUrl; + // Blazor tiered mode + var baseUrl = remoteServiceConfig.BaseUrl; client.BaseAddress = new Uri(baseUrl); AddHeaders(requestMessage); - await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, - requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty)); + await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty)); } - catch (AbpException) // Blazor-Server mode. + else { - baseUrl = NavigationManager.BaseUri; - client.BaseAddress = new Uri(baseUrl); + // Blazor server mode + client.BaseAddress = new Uri(NavigationManager.BaseUri); foreach (var header in HttpContextAccessor.HttpContext!.Request.Headers) { requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); From e4203120364751b103ad1cf2c6f3a0fe8a73e79e Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 22 Nov 2023 17:07:32 +0800 Subject: [PATCH 2/3] Update WebAssemblyLookupApiRequestService.cs --- .../Extensibility/WebAssemblyLookupApiRequestService.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs index 01378f5ddd..88df598b89 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs @@ -39,7 +39,11 @@ public class WebAssemblyLookupApiRequestService : ILookupApiRequestService, ITra var uri = new Uri(url, UriKind.RelativeOrAbsolute); if (!uri.IsAbsoluteUri) { - var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Default"); + var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultOrNullAsync("Default"); + if (remoteServiceConfig == null) + { + throw new AbpException("Remote service configuration 'Default' was not found!"); + } client.BaseAddress = new Uri(remoteServiceConfig.BaseUrl); await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(remoteServiceConfig.BaseUrl), string.Empty)); } From 7c7be20a057b95331ddbab0cf217fe7ffeb1211d Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 23 Nov 2023 13:21:36 +0800 Subject: [PATCH 3/3] Set `DecompressionMethods` for `BlazorServerLookupApiRequestService`'s http client. --- .../Server/AbpAspNetCoreComponentsServerModule.cs | 9 ++++++++- .../Extensibility/BlazorServerLookupApiRequestService.cs | 2 +- .../Extensibility/WebAssemblyLookupApiRequestService.cs | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs index 6da6e12cf4..60ee5c7b20 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/AbpAspNetCoreComponentsServerModule.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Net; +using System.Net.Http; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.StaticWebAssets; using Microsoft.AspNetCore.Http.Connections; @@ -8,6 +10,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Volo.Abp.AspNetCore.Auditing; +using Volo.Abp.AspNetCore.Components.Server.Extensibility; using Volo.Abp.AspNetCore.Components.Web; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.SignalR; @@ -30,7 +33,11 @@ public class AbpAspNetCoreComponentsServerModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { StaticWebAssetsLoader.UseStaticWebAssets(context.Services.GetHostingEnvironment(), context.Services.GetConfiguration()); - context.Services.AddHttpClient(); + context.Services.AddHttpClient(nameof(BlazorServerLookupApiRequestService)) + .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + { + AutomaticDecompression = DecompressionMethods.All + }); var serverSideBlazorBuilder = context.Services.AddServerSideBlazor(options => { if (context.Services.GetHostingEnvironment().IsDevelopment()) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs index 1acda7e066..3211aec50d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Server/Volo/Abp/AspNetCore/Components/Server/Extensibility/BlazorServerLookupApiRequestService.cs @@ -41,7 +41,7 @@ public class BlazorServerLookupApiRequestService : ILookupApiRequestService, ITr public async Task SendAsync(string url) { - var client = HttpClientFactory.CreateClient(); + var client = HttpClientFactory.CreateClient(nameof(BlazorServerLookupApiRequestService)); var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); var uri = new Uri(url, UriKind.RelativeOrAbsolute); diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs index 88df598b89..4acdafdb15 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Extensibility/WebAssemblyLookupApiRequestService.cs @@ -32,7 +32,7 @@ public class WebAssemblyLookupApiRequestService : ILookupApiRequestService, ITra public async Task SendAsync(string url) { - var client = HttpClientFactory.CreateClient(); + var client = HttpClientFactory.CreateClient(nameof(WebAssemblyLookupApiRequestService)); var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); AddHeaders(requestMessage);