Merge commit from fork

* Use Debug Mode to determine content of the ProblemDetails

* Cache the debug value
This commit is contained in:
Bjarke Berg
2024-08-19 15:05:02 +02:00
committed by GitHub
parent a36535b354
commit d0c76171dd
2 changed files with 14 additions and 9 deletions

View File

@@ -43,14 +43,14 @@ public class AspNetCoreHostingEnvironment : IHostingEnvironment
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_urlProviderMode = _webRoutingSettings.CurrentValue.UrlProviderMode;
SetSiteName(hostingSettings.CurrentValue.SiteName);
SetSiteNameAndDebugMode(hostingSettings.CurrentValue);
// We have to ensure that the OptionsMonitor is an actual options monitor since we have a hack
// where we initially use an OptionsMonitorAdapter, which doesn't implement OnChange.
// See summery of OptionsMonitorAdapter for more information.
if (hostingSettings is OptionsMonitor<HostingSettings>)
{
hostingSettings.OnChange(settings => SetSiteName(settings.SiteName));
hostingSettings.OnChange(settings => SetSiteNameAndDebugMode(settings));
}
ApplicationPhysicalPath = webHostEnvironment.ContentRootPath;
@@ -95,7 +95,7 @@ public class AspNetCoreHostingEnvironment : IHostingEnvironment
_hostingSettings.CurrentValue.ApplicationVirtualPath?.EnsureStartsWith('/') ?? "/";
/// <inheritdoc />
public bool IsDebugMode => _hostingSettings.CurrentValue.Debug;
public bool IsDebugMode { get; private set; }
public string LocalTempPath
{
@@ -188,8 +188,12 @@ public class AspNetCoreHostingEnvironment : IHostingEnvironment
}
}
private void SetSiteName(string? siteName) =>
SiteName = string.IsNullOrWhiteSpace(siteName)
private void SetSiteNameAndDebugMode(HostingSettings hostingSettings)
{
SiteName = string.IsNullOrWhiteSpace(hostingSettings.SiteName)
? _webHostEnvironment.ApplicationName
: siteName;
: hostingSettings.SiteName;
IsDebugMode = hostingSettings.Debug;
}
}