'Getting the slot name using code (staging/production)

I am trying to get the name of the slot progammatically but I am unable to do so: I have tried the apporach given in the other answer such as

trying getConfig(Website_Hostname) => this gives mywebsite.azurewebsites.net for production and mywebsite-staging.azurewebsites.net for staging but when I swap the slots this doesnt change so it will not work for me

trying getConfig(APPSETTING_WEBSITE_SITE_NAME) => this is giving me same answer for both staging and Production slot

trying getConfig(APPSETTING_KeyName) => not giving any answer

are there any other settings which I can get to differentiate between the slots and can get through code ?

can someone help me on this??



Solution 1:[1]

  • If you look at the APPSETTING WEBSITE SLOT NAME environment variable in your code, you'll notice that the value is Production while your function is in production mode, and the value is the slot name when it's in slot mode.
  • To retrieve APPSETTING WEBSITE SLOT NAME
System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process);

OR

var slot = System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process);

enter image description here

enter image description here

  • You can see WEBSITE_SLOT_NAME in AppSettings and APPSETTING_WEBSITE_SLOT_NAME in Environment Variables

  • The name of the web app once a swap is completed is the production app, there is no difference between prod and staging once the swap is completed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HarshithaVeeramalla-MT