3

I have an Azure App Service with production and staging slots. I'm running a couple of websites using virtual directories. I have tasks setup to notify me when each website has been warmed up. I'm using the WEBSITE_HOSTNAME environment variable to determine where the email is being generated and appending Prod/Staging to the subject. I also have the assembly version in the body to see what code is being warmed up.

string websiteHostName = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");

When I deploy 'Version 2' to staging I get the emails with '/staging' appended correctly and 'Version 2' in the body. When I swap the slots I get emails with '/prod' and 'Version 1' in the body.

When I check KUDU for the production slot the WEBSITE_HOSTNAME is (site name)-staging.azurewebsites.net and the value for the staging slot is (site name).azurewebsites.net. If I manually restart the staging slot the WEBSITE_HOSTNAME value gets updated to -staging.azurewebsites.net and the email I receive from the warm up process has '/staging' and 'Version 1' which is what I would expect from the warm up process when it is swapped to staging.

I have already tried using deployment slots but the swap didn't work correctly as the swap was being marked as completed before the app had warmed up completely and this caused downtime for the users.

What is the reason for the restart of the production slot when it is swapped to staging? Should the WEBSITE_HOSTNAME value be updated when this happens? I'm confused since a manual restart updates the value.

Is there a way to prevent the app from restarting when it gets swapped to staging?

Alternatively, is there a way to get the HTTP_HOST variable value?

Tom
  • 365
  • 3
  • 19

1 Answers1

2

The incorrect WEBSITE_HOSTNAME after swapped is a known issue and we are working on resolving it. Workaround is to restart which is not perfect. Another workaround is for app to ignore that environment variable and rely on the actual incoming header HTTP_HOST.

  • I tried using a similar setup to get the HTTP_HOST as I'm already using to get the WEBSITE_HOSTNAME value. When I try string httpHost = Environment.GetEnvironmentVariable("HTTP_HOST");, the value being returned is NULL. Should this work or do I need a different setup to get the HTTP_HOST value? – Tom Jun 24 '19 at 07:45
  • 1
    This bug still isn't fixed, FYI – IGx89 Mar 20 '20 at 17:28
  • Yeah, I wrote an Azure SDK WebJob that was going to log to Azure blob storage using folders named after this variable. I was so confused until I realized this is a bug. Unfortunately there are no headers to mine for the HTTP_HOST since my WebJob is not responding to a request but runs on a continuous timer – bkwdesign Jul 27 '21 at 13:37
  • Still not fixed. Seems like the solution is to use a sticky setting which is a bit redundant. – KwackMaster Mar 22 '23 at 20:49
  • Still not fixed four years later. I'm inclined to conclude this is never going to be fixed. – starskythehutch Jul 14 '23 at 14:34