本文介绍了在启动时获取azure应用服务插槽名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当asp.net核心进程启动时,如何获取我的应用程序服务的插槽(生产或暂存)的名称.

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

启动时似乎未设置HTTP_HOST环境变量,并且我没有要检查的http请求.

The HTTP_HOST environment variable doesn't appear to be set on startup and I have no http request to inspect.

推荐答案

如果要获取主机名,则可以使用环境变量 WEBSITE_HOSTNAME 来实现.

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");

如果在插槽环境中运行它,则将获得值youwebsiteName-slotName.azurewebsites.net.或者,如果您在生产环境中运行它,则将获得值youwebsiteName.azurewebsites.net.

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.

更新:

我们可以使用appsetting插槽执行此操作.

We could use the appsetting slot to do that.

1.转到插槽webApp并配置appsetting并检查插槽设置.

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

2.请使用以下代码获取插槽名称.

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

这篇关于在启动时获取azure应用服务插槽名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:46