If I understand this correctly, an alias domain is just an additional domain which points to the same server as your main domain, so you are not being redirected to the main domain? I.e the address bar still shows the URL the user used to access your site. In that case, it should be as easy as reading the host name from the current URL. You can grab that info via the IHttpContextAccessor
.
Step 1, register it as a service in the startup.cs file
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
Step 2, make your controller depend on it, via DI:
private readonly IHttpContextAccessor _httpContextAccessor;
public YourController(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
Step 3, read the info from the httpContextAccessor:
string domain = _httpContextAccessor.HttpContext.Request.Host.Value;