Getting the azure app service slot name on startup?

前端 未结 1 488
夕颜
夕颜 2021-01-14 16:58

How can I get the name of the slot (production or staging) of my app service when the asp.net core process starts.

The HTTP_HOST environment variable doesn\'t appear

相关标签:
1条回答
  • 2021-01-14 17:33

    If we want to get the host name, you could use the environment variable WEBSITE_HOSTNAME to do that.

    var hostName = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
    

    If you run it on the slot environment then you will get the value youwebsiteName-slotName.azurewebsites.net. Or if you run it on the production environment you will get the value youwebsiteName.azurewebsites.net.

    Update:

    We could use the appsetting slot to do that.

    1.Go to the slot webApp and config the appsetting and check slot setting.

    2.Please use the following code to get the slot name.

     string name = string.Empty;
     var sitName = Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SITE_NAME", EnvironmentVariableTarget.Process);
     var slotName = Environment.GetEnvironmentVariable("APPSETTING_KeyName", EnvironmentVariableTarget.Process); //APPSETTING_Test_Slot
     if (!string.IsNullOrEmpty(slotName))
     {
         name = sitName + "-" + slotName;
     }
     else
     {
         name = sitName;
     }
    
    0 讨论(0)
提交回复
热议问题