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.
Azure Functions deployment slots allow your function app to run different instances called "slots". Slots are different environments exposed via a publicly available endpoint. One app instance is always mapped to the production slot, and you can swap instances assigned to a slot on demand.
Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it . NET, . NET Core, Java, Ruby, Node. js, PHP, or Python.
You can find the connection string under Access Keys in the Azure portal.
Deployment slots are live apps with their own host names. App content and configurations elements can be swapped between two deployment slots, including the production slot.
When you deploy your web app, web app on Linux, mobile back end, or API app to Azure App Service, you can use a separate deployment slot instead of the default production slot when you're running in the Standard, Premium, or Isolated App Service plan tier. Deployment slots are live apps with their own host names.
To limit public access to the deployment slot, see Azure App Service IP restrictions. The new deployment slot has no content, even if you clone the settings from a different slot. For example, you can publish to this slot with Git. You can deploy to the slot from a different repository branch or a different repository.
The app type is shown as App Service (Slot) to remind you that you're viewing a deployment slot. Select Delete on the command bar. This article uses the Azure Az PowerShell module, which is the recommended PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell.
Creating an app service slot 1 Navigate to your Azure app service created in your environment. 2 Click on the deployment slot in the left side panel and choose ‘add slots’ to create your staging environment. 3 Give it a name like “Staging” so that it will be easy to identify. More ...
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With