Get the real front end domain name in Azure front door


Written by Brett Andrew 27/02/2020

When using Azure's Front Door, the backend .net core (2.2) services show the backend url. When you have multiple frontend domains and each represents a different client or instance, you need to use the front end domain.

The following functions will help you get the correct domain name.

Front door puts two header records in for you, you just need to check to see if they are present (if not then the current session did not come from the front door and you can use the url directly).

Headers["X-Forwarded-Host"]

and

Headers["X-Forwarded-Port"]


Usage Example


  public string CurrentURL()
        {

            string tmpForwardedForHost = httpContextAccessor.HttpContext.Request.Headers["X-Forwarded-Host"];
            if (tmpForwardedForHost !=null && tmpForwardedForHost.ToString()!="")
            {
                return "https://" + tmpForwardedForHost.ToString();
            }
            else
            {
                return "https://" + httpContextAccessor.HttpContext.Request.Host.Value;
            }
            
        }


Comments or question? Log in for the discussion or send your comment using this form.

Contact us

powered by mition