Get site name from appsettings if possible

This commit is contained in:
Mole
2022-01-31 10:12:02 +01:00
parent c0dfb33916
commit bdcb5d859e
2 changed files with 22 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Configuration.Models
/// <summary>
/// Gets or sets a value for the location of temporary files.
/// </summary>
[DefaultValue(StaticLocalTempStorageLocation)]
[DefaultValue(StaticLocalTempStorageLocation)]
public LocalTempStorage LocalTempStorageLocation { get; set; } = Enum<LocalTempStorage>.Parse(StaticLocalTempStorageLocation);
/// <summary>
@@ -31,5 +31,10 @@ namespace Umbraco.Cms.Core.Configuration.Models
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
[DefaultValue(StaticDebug)]
public bool Debug { get; set; } = StaticDebug;
/// <summary>
/// Gets or sets a value specifying the name of the site.
/// </summary>
public string SiteName { get; set; }
}
}

View File

@@ -37,7 +37,16 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_urlProviderMode = _webRoutingSettings.CurrentValue.UrlProviderMode;
SiteName = webHostEnvironment.ApplicationName;
SetSiteName(hostingSettings.CurrentValue.SiteName);
// 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));
}
ApplicationPhysicalPath = webHostEnvironment.ContentRootPath;
if (_webRoutingSettings.CurrentValue.UmbracoApplicationUrl is not null)
@@ -53,7 +62,7 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
public Uri ApplicationMainUrl { get; private set; }
/// <inheritdoc/>
public string SiteName { get; }
public string SiteName { get; private set; }
/// <inheritdoc/>
public string ApplicationId
@@ -198,7 +207,10 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
}
}
}
private void SetSiteName(string siteName) =>
SiteName = string.IsNullOrWhiteSpace(siteName)
? _webHostEnvironment.ApplicationName
: siteName;
}
}