| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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<string> GetRedirectAllowedExternalWebSites()
- {
- var values = _appConfiguration["App:RedirectAllowedExternalWebSites"];
- return values?.Split(',').ToList() ?? new List<string>();
- }
- 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 + ".");
- }
- }
|