Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the azure app service slot name on startup?

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.

like image 749
Clement Avatar asked May 03 '18 05:05

Clement


People also ask

What is Azure App Service slot?

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.

What is App Service name in Azure?

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.

How do I get Azure app configuration connection string?

You can find the connection string under Access Keys in the Azure portal.

What is deployment slot setting in Azure App Service?

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.

What are deployment slots in Azure App service?

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.

How do I limit public access to Azure App service deployment slots?

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.

How do I delete an app from an azure azure deployment slot?

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.

How to create a staging environment in Azure App service?

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 ...


1 Answers

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.

enter image description here

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;
 }
like image 88
Tom Sun - MSFT Avatar answered Oct 12 '22 22:10

Tom Sun - MSFT