Csp: localhost
This commit is contained in:
parent
44a1021614
commit
112d796b72
@ -32,6 +32,7 @@ public class Tenant : IMapFrom<DbTenant>
|
||||
public const int DefaultTenant = -1;
|
||||
|
||||
public static readonly string HostName = Dns.GetHostName().ToLowerInvariant();
|
||||
public const string LocalHost = "localhost";
|
||||
|
||||
private List<string> _domains;
|
||||
|
||||
|
@ -47,6 +47,7 @@ public class CspSettingsHelper
|
||||
private readonly TenantManager _tenantManager;
|
||||
private readonly CoreSettings _coreSettings;
|
||||
private readonly IDistributedCache _distributedCache;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public CspSettingsHelper(
|
||||
@ -55,6 +56,7 @@ public class CspSettingsHelper
|
||||
TenantManager tenantManager,
|
||||
CoreSettings coreSettings,
|
||||
IDistributedCache distributedCache,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_settingsManager = settingsManager;
|
||||
@ -62,21 +64,34 @@ public class CspSettingsHelper
|
||||
_tenantManager = tenantManager;
|
||||
_coreSettings = coreSettings;
|
||||
_distributedCache = distributedCache;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public async Task<string> Save(IEnumerable<string> domains)
|
||||
{
|
||||
var headerKey = GetKey(_tenantManager.GetCurrentTenant().GetTenantDomain(_coreSettings));
|
||||
var tenant = _tenantManager.GetCurrentTenant();
|
||||
var domain = tenant.GetTenantDomain(_coreSettings);
|
||||
List<string> headerKeys = new()
|
||||
{
|
||||
GetKey(domain)
|
||||
};
|
||||
|
||||
if (domain == Tenant.LocalHost && tenant.Alias == Tenant.LocalHost)
|
||||
{
|
||||
headerKeys.Add(GetKey(Tenant.HostName));
|
||||
headerKeys.Add(GetKey(_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString()));
|
||||
}
|
||||
|
||||
var headerValue = CreateHeader(domains);
|
||||
|
||||
if (!string.IsNullOrEmpty(headerValue))
|
||||
{
|
||||
await _distributedCache.SetStringAsync(headerKey, headerValue);
|
||||
await Parallel.ForEachAsync(headerKeys, async (headerKey, _) => await _distributedCache.SetStringAsync(headerKey, headerValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
await _distributedCache.RemoveAsync(headerKey);
|
||||
await Parallel.ForEachAsync(headerKeys, async (headerKey, _) => await _distributedCache.RemoveAsync(headerKey));
|
||||
}
|
||||
|
||||
var current = _settingsManager.Load<CspSettings>();
|
||||
|
Loading…
Reference in New Issue
Block a user