Browse Source
Refactor timezone retrieval logic to prioritize settings, request, and server fallback
pull/22236/head
maliming
1 year ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
1 changed files with
6 additions and
8 deletions
-
framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Timing/AbpTimeZoneMiddleware.cs
|
|
@ -21,21 +21,19 @@ public class AbpTimeZoneMiddleware : AbpMiddlewareBase, ITransientDependency |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
string? timezone = null; |
|
|
// Try to get the timezone from the setting system first
|
|
|
|
|
|
var settingProvider = context.RequestServices.GetRequiredService<ISettingProvider>(); |
|
|
if (!context.RequestServices.GetRequiredService<ICurrentUser>().IsAuthenticated) |
|
|
var timezone = await settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone); |
|
|
{ |
|
|
|
|
|
timezone = await GetTimezoneFromRequestAsync(context); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (timezone.IsNullOrWhiteSpace()) |
|
|
if (timezone.IsNullOrWhiteSpace()) |
|
|
{ |
|
|
{ |
|
|
var settingProvider = context.RequestServices.GetRequiredService<ISettingProvider>(); |
|
|
// Try to get the timezone from the HTTP request if the setting is not available
|
|
|
timezone = await settingProvider.GetOrNullAsync(TimingSettingNames.TimeZone); |
|
|
timezone = await GetTimezoneFromRequestAsync(context); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (timezone.IsNullOrWhiteSpace()) |
|
|
if (timezone.IsNullOrWhiteSpace()) |
|
|
{ |
|
|
{ |
|
|
|
|
|
// Try to get the timezone from the current running server if the setting and request are not available
|
|
|
timezone = context.RequestServices.GetRequiredService<ITimezoneProvider>().GetCurrentIanaTimezoneName(); |
|
|
timezone = context.RequestServices.GetRequiredService<ITimezoneProvider>().GetCurrentIanaTimezoneName(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|