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
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;
}