using Abp.Extensions; using VberZero.Configuration; namespace VberZero.DomainService.Url; public abstract class WebUrlServiceBase { public const string TenancyNamePlaceHolder = "{TENANCY_NAME}"; public abstract string WebSiteRootAddressFormatKey { get; } public abstract string ServerRootAddressFormatKey { get; } public string WebSiteRootAddressFormat => _appConfiguration[WebSiteRootAddressFormatKey] ?? "https://localhost:62114/"; public string ServerRootAddressFormat => _appConfiguration[ServerRootAddressFormatKey] ?? "https://localhost:62114/"; public bool SupportsTenancyNameInUrl { get { var siteRootFormat = WebSiteRootAddressFormat; return !siteRootFormat.IsNullOrEmpty() && siteRootFormat.Contains(TenancyNamePlaceHolder); } } private readonly IConfigurationRoot _appConfiguration; protected WebUrlServiceBase(IAppConfigurationAccessor configurationAccessor) { _appConfiguration = configurationAccessor.Configuration; } public string GetSiteRootAddress(string tenancyName = null) { return ReplaceTenancyNameInUrl(WebSiteRootAddressFormat, tenancyName); } public string GetServerRootAddress(string tenancyName = null) { return ReplaceTenancyNameInUrl(ServerRootAddressFormat, tenancyName); } public List GetRedirectAllowedExternalWebSites() { var values = _appConfiguration["App:RedirectAllowedExternalWebSites"]; return values?.Split(',').ToList() ?? new List(); } private string ReplaceTenancyNameInUrl(string siteRootFormat, string tenancyName) { if (!siteRootFormat.Contains(TenancyNamePlaceHolder)) { return siteRootFormat; } if (siteRootFormat.Contains(TenancyNamePlaceHolder + ".")) { siteRootFormat = siteRootFormat.Replace(TenancyNamePlaceHolder + ".", TenancyNamePlaceHolder); } if (tenancyName.IsNullOrEmpty()) { return siteRootFormat.Replace(TenancyNamePlaceHolder, ""); } return siteRootFormat.Replace(TenancyNamePlaceHolder, tenancyName + "."); } }