Getting the azure app service slot name on startup?

为君一笑 提交于 2019-12-22 18:46:23

问题


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 to be set on startup and I have no http request to inspect.


回答1:


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


来源:https://stackoverflow.com/questions/50147803/getting-the-azure-app-service-slot-name-on-startup

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