Getting the azure app service slot name on startup?

十年热恋 提交于 2019-12-06 11:09:02

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;
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!